Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view the commands you use most frequently on Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to check your most frequently used commands on Linux. It is very detailed and has some reference value. If you are interested, you must finish reading it.

Check your own most frequently used commands on Linux

In Linux, the history file ~ / .bash_history records all the commands you have entered in the terminal, so we can use this file to find the commands you use most frequently.

The specific practices are as follows:

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

The results of the above command will show the five commands that users use most frequently on Linux.

The output is as follows:

153 sudo118 ls33 cd30 ssh39 git

The result is very refreshing and intuitive!

So, do you know the specific function of each part of the above command? Now, let's explain it in detail.

First, let's look at the output of the history command:

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 seen on Ubuntu. If you see it on other platforms, such as CentOS, the result will be a different situation, and the corresponding command will need to be changed slightly.

Awk'{print $2} 'prints the second column string from the history file without displaying command options and arguments

Sort arranges all lines alphabetically

Uniq-c deletes duplicate rows and counts them

Sort-nr sorts in reverse according to the statistics returned by the uniq command

Tip: you can use Explain Shell to find a functional description of each option in the command.

As you can see from the results, sudo is the most frequently used command for current users, using it 153 times.

The display of the result is in descending order, and if you want it to be 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 them with the previous command to see their differences.

The output is as follows:

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 command.

$history | awk'{print $2}'| sort | uniq-c | sort-nr is all the contents of the article "how to check your most frequently used commands on Linux". Thank you for reading! Hope to share the content to help you, more related 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report