We may have to use a lot of Linux command lines every day. We also know some tips on how to use them on the Internet, but if we don't do it often, we may forget how to use them. So I decided to list all the little tips and tricks that you might forget, or maybe something entirely new to you.
Display the output as a tabular format
Sometimes, when you see the output from the command line, the output is difficult to identify because of the string overcrowding (for example, the output of the Mount command). What if what we see is a table? In fact, it is very easy to do!
Mount | Column–t:
In this case, the form of the output is aesthetically pleasing because of the space left in the content. What if the delimiter you want is something else, such as a colon, and how do you do it? (for example, used in the output of CAT/ETC/PASSWD)
Just use the-s parameter to specify the delimiter, as follows.
cat/etc/passwd | COLUMN-T-S:
Execute a command repeatedly until it runs successfully
If you search for this feature on Google, you'll find a lot of people asking how to repeat the command until the command returns and works correctly. Google's recommendations include pinging the server until it becomes idle, checking to see if a file with a specific extension has been uploaded to a particular directory, and checking to see if a particular URL already exists, and so forth.
You can also implement this function by using a loop of while true:
In the above example, >/dev/null 2>&1 will redirect the output of the program to/dev/null. Standard errors and standard output will be included.
This is one of the coolest Linux command-line tricks I've seen.
Sort processes by memory resource usage
PS aux | SORT-RNK 4:
Sort processes by CPU resource usage
PS aux | Sort-nk 3:
If you want to check your machine architecture, then execute getconf long_bit.
Multiple log files can be viewed at the same time
There is no doubt that you may already be using the tail command to view the log file, but there may be times when you want to be able to view multiple log files at the same time. Support text highlighting, content filtering, and more features you might need using the Multi-tail command:
If this command is not available in the system, run the Apt-get install multitail command to load it.
Go back to the last directory you've been working on.
Simply typing the CD-it will return to the previous directory you have manipulated.
Allow noninteractive Shell sessions to interact
To do this, change the settings from ~/.BASHRC to ~/.bash_profile.
Timed, monitored command output
With the Watch Command (watch Df-h), you can see any output of any command. For example, you can see how much space is available and how it's used.
By using the Watch command to manipulate changing data, you can imagine what you can do with it.
Continue running the program after the session is switched off
If you run a program in the background and then you turn off the shell session, the program running in the background will be killed by your shell. How do you keep your program running after you close the shell?
This can be done with the nohup command-this instruction does not do the hang-up operation:
Nohup wget Site.com/file.zip
This command is one of the easiest Linux command-line tricks to forget because many of us use the screen environment of another class command:
This generates a file named Nohup.out in the same directory that contains the output of the running program:
The order is cool, isn't it?
Automatically answer yes or no to any command
If you want to automate the process of saying yes to your users, you can do this by using the Yes Command: yes | Apt-get Update.
Perhaps what you want to do is to say "No" automatically. This can be used with Yes No | command to implement.
Create a file with the specified size
You can use the DD command to create a file with the specified size: dd if=/dev/zero of=out.txt bs=1m count=10.
This creates a file with a size of 0 MB and populates it with the contents:
Run the last command as a root user
Sometimes you forget to use sudo before commands that require root privileges. You don't need to rewrite the order at this time. Just type sudo on the line!
To record a command line session
If you want to record what you've tapped on the shell screen, you can use the script command to save all the typing to a file named Typescriptscript.
Once you have typed the exit command, all commands will be written to the file so that you can go back and look at it afterwards.
Replace whitespace with a label symbol
You can replace any character with the TR command, which is handy: Cat Geeks.txt | TR ': [space]: ' \ t ' > OUT.txt.
Convert the contents of a file to uppercase or lowercase
This can be achieved: Cat MyFile | TR A-Z a-z> output.txt.
Powerful Xargs command
The Xargs command is one of the most important Linux command-line tricks. You can use this command to pass the output of the command as an argument to another command. For example, search for a PNG file and then compress it or other actions:
Find. -name *.png-type F-print | Xargs Tar-cvzf images.tar.gz
Or you have a list of URLs in your file, and what you want to do is download or process the URLs in different ways, and you can do this:
Cat Urls.txt | Xargs wget
Please remember that the output of the first command is passed at the end of the Xargs command.
What if the command needs the output of the intermediate process? This is simple!
You only need to use {} and combine the-i parameter. Replace the parameters in the place where the output of the first command should go, as shown below:
Ls/etc/*.conf | xargs-i cp {}/home/likegeeks/desktop/out
This is just a few of the Linux command-line tricks. You can use other commands to do something more HAPPY, such as awk commands and SED commands!
If you know some of the other geek commands I have not mentioned here, please comment.
The most practical techniques for using Linux commands