You know yourself what is the most frequently used several Linux command it?

I do not know since contact with Linux, which commands are used, in which the most commonly used commands are what?

One of my most commonly used command is sudo, because I use every day to install it on Linux, update, delete, and various other packages require superuser privileges.

Then you know you are their most frequently used commands which a few do? Today we'll take a look at themselves in the use of Linux command of the most frequently used it.

View your most frequently used commands on Linux

In Linux, the history file ~ / .bash_history will record all the commands you entered in the terminal, so we can find the commands you use most often by this document.

Specifically, the following:

$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5

The results above command will display the five most frequently used commands users on Linux.

Output:

153 sudo118 ls33 cd30 ssh29 git

This result is very refreshing and intuitive!

Then, the various parts of this command above you know its specific role in it? Now, let's explain in detail.

First we look at the output of the command history:

alvin@alvin-pc:~$ history 743 sudo apt-get update 744 sudo apt-get upgrade 745 ls 747 ls 748 git status

This is the result on Ubuntu to see if the other platforms, such as CentOS, see the result would be another case, the corresponding commands also require small change it.

  • awk '{print $ 2}' printing of the two strings from the history file, no display command options and parameters

  • alphabetical sort all rows

  • uniq -c delete duplicate lines and keep them counting statistics

  • sort -nr Reverse Sort according to statistics uniq command returns

  • Tip: You can use the Find command to ExplainShell functional description of each option.

We can see from the results, sudo is currently the most frequently used commands that the user used 153 times.

The results are displayed in descending order, if you want it displayed in ascending order, you need to use the following command:

$ history | awk {'print $2'} | sort | uniq -c | sort -n | tail -n5

You can compare the previous command to view their differences.

Output:

29 git  
30 ssh  
33 cd  
118 ls  
153 sudo

If you do not want to limit the number of results, simply delete the last part of the above commands can be.

$ history | awk '{print $2}' | sort | uniq -c | sort -nr


Guess you like

Origin blog.51cto.com/14414295/2484877