In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what practical Linux command line skills, I believe most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The output is displayed as a table
Sometimes, when you see the output of a command, the output may not be recognized due to overcrowded strings (for example, the output of the mount command). What about showing it through the table? It's easy to do!
Mount | column-t:
In this example, the output is well formatted because of the spaces. What if the separator is something else, like a colon? (for example, in the output of cat/etc/passwd).
Specify the delimiter-s parameter, like below.
Cat / etc/passwd | column-t-s:
Repeat a command until it runs successfully
If you search for this feature on Google, you will find that many people will ask how to repeat the command until it returns successfully and works properly. For example, include a ping server until it is online, check whether files with a specific extension are uploaded from a specific directory, check whether a specific URL already exists, and so on.
You can use a while true loop to do this:
In this example, > / dev/null 2 > & 1 redirects the output of your program to / dev/null. Both Standard Error and Standard Out are included.
For me, this is one of the coolest linux command line techniques.
Sort processes by memory utilization
Ps aux | sort-rnk 4:
Sort processes by CPU utilization
Ps aux | sort-nk 3:
Check your architecture and execute getconf LONG_BIT.
View multiple log files at the same time
You can use the tail command to view your log without a problem, but sometimes you may want to view multiple log files. You need to use multi-tail commands that support text highlighting, filtering, and more:
If you don't have this command on your system, you can use apt-get install multitail.
Go back to your previous catalog.
Just type cd-and you will return to the previous directory.
Do a non-interactive Shell conversation interaction
To do this, you need to change the setting from ~ /. Bashrc to ~ /. Bash_profile.
Monitor command output periodically
Using the observe command (watch df-h), you can see the output of any command. For example, you can look at free space and how it is growing.
With the watch command, you can imagine what you can do with variables.
Run the program after closing the session
When you run any program in the background, it will be closed by your shell. How can you continue to run this program after you close shell?
This can be done by using the nohup command, which means there is no hang-up:
Nohup wget site.com/file.zip
This command is one of the most forgotten Linux command line tricks, because many of us use another command, screen:
A file called nohup.out will be generated in the same directory that contains the output of the running program:
Orders are cool, aren't they?
Automatically answer yes or no to any command
If you want to automate the process of user typing yes
You can use the yes command: yes | apt-get update.
Or if you want to type no automatically, you can use yes no | command.
Create a file of the specified size
You can use the dd command to create a file of a specified size: dd if=/dev/zero of=out.txt bs=1M count=10.
Let's create a file with a size of 10MB filled with 0:
Run the command of * as root user
Sometimes you want to run the command as root, but forget to enter the sudo command. You don't have to re-type; just type sudo!
Record your command line conversation.
If you want to record what you type on shell, you can use the script command to save all your input to a file called typescript:script.
Once you type exit, all commands you enter will be written to that file, and you can re-view it later.
Replace spaces with placeholders
You can use the tr command instead of any other character, which is convenient: cat geeks.txt | tr': [space]:'\ t'> out.txt.
Convert files to uppercase or lowercase
You can use:
Cat myfile | tr Amurz Amurz > output.txt
Powerful Xargs command
The xargs command is one of the most important Linux command-line techniques. You can use this command to pass the output of the command as an argument to another command. For example, you can search for a PNGpng file and compress it or do anything about it:
Find. -name * .png-type f-print | xargs tar-cvzf images.tar.gz
Or maybe you have a URL list in a file that you want to download or deal with differently:
Cat urls.txt | xargs wget
Remember, the output of * commands is passed to the end of the xargs command.
What if your command needs to be output in the middle? simple!
Just use {} with the-I parameter, as follows, replace the position of the parameter with the output result of * commands:
Ls / etc/*.conf | xargs-I cp {} / home/likegeeks/Desktop/out are all the contents of this article entitled "what are the practical Linux command line tips?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.