In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you about the use of commands on Linux, I believe that 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!
First, keep in mind that a typical command history might look like this. Notice that the command is displayed after the command serial number, followed by its arguments.
91 sudo apt-get install ccrypt ^ +-- command
Note that the history command follows the settings of HISTSIZE, which determines how many commands are retained. It could be 500, 1000 or more. If you don't like its settings, you can add or change HISTSIZE settings in .bashrc or other startup files.
$echo $HISTSIZE1000 $history | wc-L1000 $grep HISTSIZE ~ / .bashrc # for setting history length see HISTSIZE and HISTFILESIZE in bash (1) HISTSIZE=1000
One of the main benefits of writing down a large number of commands is that it allows you to easily rerun commands you used in the past without having to re-enter or remember them. It also makes it easy for you to see how much work you have done in a task. When you use the history command alone, you will see something like this, the earliest one at the front:
$history 7 vi tasks 8 alias 9 echo $HISTTIMEFORMAT 10 history 11 date …
To view the latest use of commands, you need to view the tail of the recorded command:
$history | tail-4 1007 echo $HISTSIZE 1008 history | wc-l 1009 history 1010 history | tail-4
In addition, you can use the tail command to view the tail of the .bash _ history file, but the number displayed by the history command allows you to rerun the command by entering a number such as! 1010, which is usually more useful.
To provide a summary of commands used (such as vi and echo), you can first use awk to separate the command from other information saved in history:
$history | awk'{print $2} 'vialiasechohistorydate...
If you pass the list of commands in the history to the sort command to group the commands alphabetically, you get the following:
$history | awk'{print $2}'| sort7z7zaliasaproposcdcd...
Next, pass the output of the sort command to uniq-c, which calculates how many times each command has been used:
$history | awk'{print $2}'| sort | uniq-c 2 7z 1 alias 2 apropos 38 cd 21 chmod …
Finally, add a second sort command to sort the command group count in reverse order, which first lists the most commonly used commands:
$history | awk'{print $2}'| sort | uniq-c | sort-nr 178 ls 95 vi 63 cd 53 sudo 41 more …
This gives you an idea of the commands you use most, but does not include any commands that you might deliberately delete from the history file, such as:
HISTIGNORE= "pwd:clear:man:history" when the history format is modified
For the default history format, the first field in the history command output will be the sequence number of each command, and the second field will be the command used. Therefore, all the above awk commands are set to display $2.
$alias cmds='history | awk'\'{print $2}'\'| sort | uniq-c | sort-nr'
If you add the date and time to the history command as follows, you must also modify the alias you set:
$echo $HISTTIMEFORMAT%d/%m/%y% T
This date / time information is sometimes helpful, but it means that you have to select the fourth field of the history command instead of the second field to summarize the command, because your history entry will look like this:
91 05ax 07 sudo apt-get install ccrypt 20 16:37:39 SQL ^ +-- command
Therefore, after changing $2 to $4, the alias used to check the history command will be changed to this:
$alias cmds='history | awk'\'{print $4}'\'| sort | uniq-c | sort-nr'
Aliases can be saved in .bashrc or other startup files, and be sure to insert a backslash before the $symbol so that bash does not try to interpret $4.
Alias cmds='history | awk'\'{print\ $2}'\'| uniq-c | sort-nr'alias cmds='history | awk'\'{print\ $4}'\'| uniq-c | sort-nr'
Note that the date and time information is saved separately from the command itself in the history file. Therefore, when you add this information, the number of lines in the bash history file doubles, although not when the history command outputs:
$wc-l. Bash _ history2000. Bash _ history$ history | wc-L1000 is all the content of the article "what do you think of the use of commands on Linux"? 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.