Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Improve your productivity. What specific linux skills do you use?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Improve your work efficiency linux skills specific use, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Some tips in linux can greatly improve your productivity. This article details those linux techniques that improve productivity or are simple but effective.

Command editing and cursor movement

There are many keyboard shortcuts that can help us correct our commands. Next, use the word cursor instead of the cursor position.

Delete the command text from the beginning to the cursor

Ctrl + u, for example:

$cd / proc/tty;ls-al cursor

If you use the ctrl + u shortcut key at this time, the command will be cleared without long pressing the backspace key.

Delete the command text from the cursor to the end

Ctrl+k, for example:

$cd / proc/tty cursor; ls-al

If you use the ctrl + k shortcut key at this time, the command text from the beginning to the end of the cursor will be deleted.

There are other operations that no longer give examples, such as:

Ctrl + a: move the cursor to the beginning of the command

Ctrl + e: move the cursor to the end of the command

Alt f: move the cursor forward one word

Alt b: move the cursor forward one word

Ctrl w: delete a word (a string separated by spaces)

Quick execution of historical commands

We all know that history records the execution of historical commands, and using the numbers before the! + historical command, you can quickly execute historical commands. For details, please refer to "in Linux"! The amazing usage of ". Alternatively, you can use ctrl+r to search for executed commands.

Part of the history command view

History will display a large number of historical commands, while fs-l will only show some of them.

View logs in real time $tail-f filename.log

Tail-f plus file name, you can display the contents of the log file in real time. Of course, a similar effect can be achieved by using the less command to view the contents of the file and using the shift+ f key.

Disk or memory check how to know whether the current disk is full? $df-h

/ dev/sda14 4.6G 10m 4.4G 1% / tmp

/ dev/sda11 454M 366M 61m 86% / boot

/ dev/sda15 55G 18G 35G 35% / home

/ dev/sda1 256M 31M 226M 12% / boot/efi

Tmpfs 786M 64K 786m 1% / run/user/1000

Use the df command to quickly view the disk usage of each mount path.

The amount of space occupied by each subdirectory of the current directory

If you already know that the home directory takes up a lot of space, you want to know the occupation of each directory under the home directory:

$du-h-max-depth=1 / home (or-d 1)

18G / home/hyb

16K / home/lost+found

18G / home/

The directory depth is specified here, otherwise, it will recursively count the space occupied by subdirectories, so you can try it on your own.

Current memory usage $free-h

Total used free shared buff/cache available

Mem: 7.7G 3.5G 452M 345M 3.7G 3.5G

Swap: 7.6G 0B 7.6G

From the results of free, it is easy to see how much total memory is currently, how much memory is left available, and so on.

Use the-h parameter

I don't know if you've noticed that we used the-h parameter in the previous commands, and its function is to make the result human-readable, so we see that it is rendered in units such as GForce M, etc., if you don't use the-h parameter, you can try what the result will look like.

Find the process id by name

To quickly and directly find the process id, you can use:

$pgrep hello

22692

Or:

$pidof hello

22692

Where hello is the process name.

Kill the process by name

Generally, we can use kill-9 pid to kill a process, but we need to find the process id of the process first. In fact, we can also kill the process directly by name, for example:

$killall hello

Or:

$pkill hello

View process run time

You can use the following command to see when the process has run:

$ps-p 24525-o lstart,etime

STARTED ELAPSED

Sat Mar 23 20:52:08 2019 02:45

24525 of these are the process id for which you want to view the process.

Fast directory switching

Cd-go back to the previous directory

Cd returns to the user's home directory

Multiple command execution

We know that multiple commands can be executed with semicolon separation, such as:

$cd / temp/log/;rm-rf *

But if the current directory is the / directory and the / temp/log directory does not exist, an exciting scene will occur:

Bash: cd: / temp/log: No such file or directory

(suddenly fell silent)

Because more than one command can be executed, but the later will not be executed because the previous command fails, therefore, after the cd execution fails, the rm-rf * will continue to be executed, and the result can be imagined because it is in the / directory.

So you still think this kind of accident happened without knowing anything about the power of rf-rf *?

What if it's solved? It's simple to use & &, for example:

$cd / temp/log/&&rm-rf *

This ensures that the previous command is executed successfully before the latter one is executed.

View compressed log files

Sometimes the log file is compressed, so can you slack off and check it? Of course you can.

For example:

$zcat test.gz

Test log

Or:

$zless test.gz

Test log

Delete garbled files

Whether it is their own accidental creation or program exception creation, there will inevitably be some strangely named or garbled files, how to delete it? Refer to "several ways to delete files with special names in linux".

Empty the contents of the file

For example, there is a large file that you want to delete quickly or do not want to delete, but want to empty the content:

> filename

Record and print the log to the console at the same time.

In the execution of shell scripts, logs are often redirected, but in this case, the console does not print, how to make it possible to record log files and output logs to the console?

$. / test.sh | tee test.log

Terminate and resume process execution

We use ctrl+z to suspend the execution of a process, or we can use fg to resume execution. For example, we use the

$cat filename

When we find that there may be a lot of content in the file, we use ctrl+z to pause the program, and if we want to continue execution from the previous place, we only need to use the fg command to resume execution. Or use bg to keep the process running in the background.

Calculate the running time of the program

We may write some Mini Program and want to know when it is running. In fact, we can make good use of the time command to help us calculate, for example:

$time. / fibo 30

The 30 result is 832040

Real 0m0.088s

User 0m0.084s

Sys 0m0.004s

It displays the system time, the user time, and the total time actually used.

View the top 10 memory-consuming processes $ps-aux | sort-k4nr | head-n 10

Here a combination of ps,sort,head commands, you can refer to the "ps command details", "a command to help you sort the text" and "linux common commands-text view article".

Quickly find the commands you need

We all know that man can view the help manual for commands, but what if we want a feature but don't know which command to use? Don't worry, you can still use man:

$man-k "copy files"

Cp (1)-copy files and directories

Cpio (1)-copy files to and from archives

Git-checkout-index (1)-Copy files from the index to the working tree

Gvfs-copy (1)-Copy files

Gvfs-move (1)-Copy files

Install (1)-copy files and set attributes

Use the-k parameter so that all the help manuals related to copy files are displayed.

Copy and paste under the command line

We know that copy can no longer be ctrl + c on the command line, because it means terminating the current process, while copy and paste under the console requires the following keyboard shortcuts:

Ctrl + insert

Shift + insert

Search for a file that contains a string

For example, to find a file that contains a test string in the current directory:

$grep-rn "test"

Test2.txt:1:test

It can find the line of the file in which the string is located.

Screen freeze

When the program is running, the terminal may output a large number of logs, you want to simply check, but do not want to record the log file, you can use the ctrl+ s key to freeze the screen, so that the log no longer continues to output, and if you want to restore, you can use ctrl+q to exit the freeze.

Edit a text file without an editor

If you don't even have a basic vi editor on some systems, you can edit the content in the following ways:

$cat > file.txt

Some words

(ctrl+d)

After editing, ctrl+d can save it.

View elf file to view elf file header information

For example:

$readelf-h filename

In the display results, we can see the running platform, elf file type, size side, and so on.

Check whether an interface $nm filename is included in the library | grep interface

This is to see if the interface interface is included in the file filename, provided that the file contains a symbol table.

After reading the above, have you mastered the specific methods of linux skills to improve your work efficiency? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report