In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the most easily forgotten Linux commands, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Make a clear table of the output
When using the command line, you can often see that the output is a mess: there are so many strings huddled together that you can't see what the output is, so try the mount command.
To see more clearly, we can convert the output into a table by adding a few characters:
Mount | column-t:
In this small example, we use spaces to separate the output into a table, and the whole interface is much clearer and more beautiful in an instant. If you don't like spaces as delimiters, you can replace them with other ones, such as colons (:).
It's still very simple: you just need to use the-s parameter at the end to make the corresponding separator:
Cat / etc/passwd | column-t-s:
Repeat a command until it runs successfully
I did a special search before writing this article. On Google, many people are asking how to implement the operation of repeating the command until it succeeds. The ping server is mentioned in the search results until it becomes free, or check to see if a specific file has been uploaded to a directory, and then check to see if a specified link exists.
But you still have other options, such as using the while true loop to get things done:
In the above example, > / dev/null 2 > & 1 redirects the program's output to / dev/null. Both standard error and standard output are included.
This is one of the coolest Linux command line techniques I think.
Sort processes by the amount of memory resources used
Ps aux | sort-rnk 4:
Sort processes by the amount of CPU resources used
Ps aux | sort-nk 3:
If you want to check your machine architecture, execute getconf LONG_BIT.
Can view multiple log files at the same time
What commands do most people use to check their logs? The answer may be the tail command. However, tail can be troublesome when you want to view a lot of log files. At this time, it's our multi-tail 's turn to take the stage! It not only supports text highlighting, but also supports content filtering and more other features.
Sometimes you need to install it to run this command, but it's also very simple and apt-get install multitail is easy to do.
Go back to the last directory you manipulated.
The operation to return to the previous directory is very simple, cd-is fine.
Make non-interactive Shell sessions interactive
To do this, change the setting from ~ / .bashrc to ~ / .bash_profile.
Timed monitoring command output
Using the watch command (watch df-h), you can see any output of any command. For example, you can look at the available space and its growth in usage.
By using the watch command to manipulate changeable data, you can imagine what you can do with it.
Continue to run the program after the session is closed
Normally, you run a background program that will be killed when you close the shell session. In some cases, what should I do to keep the program running?
This can be done with the nohup command-this instruction means no hang-up operation:
Nohup wget site.com/file.zip
Most people don't know how to use this command, thanks to the screen environment:
This generates a file named nohup.out 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 Yes process that you need to say to the user, you can use the yes command to do this: yes | apt-get update.
Maybe what you want to do is say "No" automatically. This can be done using the 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.
This creates a 10-MB file with zeros as the content:
Run a command as the root user
Sometimes you forget to type sudo before a command that requires root permission. You don't have to rewrite the command at this point; just type sudo! Just do it.
Record a command line session
If you want to record what you typed on the shell screen, you can use the script command to save all typed content to a file called typescriptscript.
After you type the exit command, all commands will be written to the file so that you can look back later.
Replace spaces with label symbols
You can replace any character with the tr command, which is very convenient to use: cat geeks.txt | tr': [space]:''> out.txt.
Convert the contents of the file to uppercase or lowercase
It can be implemented as follows: cat myfile | tr a murz 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, search for a png file and compress it or something else:
Find. -name * .png-type f-print | xargs tar-cvzf images.tar.gz
Or if you have a list of URL in your file, and what you want to do is download or process the URL in different ways, you can do this:
Cat urls.txt | xargs wget
Please remember that the output of * commands is passed at the end of the xargs command.
What if the command requires the output of an intermediate procedure? It's easy!
Just use {} and combine the-I parameter. Replace the parameter where the output of the * command should go, as shown below:
Ls / etc/*.conf | xargs-I cp {} / home/likegeeks/Desktop/out
These are just a few of the Linux command line tricks. You can use other commands to do more HAPPY things, such as awk commands and sed commands!
These are all the contents of the article "what are the most easily forgotten Linux commands?" 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.