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 check your own most frequently used commands on Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you how to view your own most frequently used commands on Linux, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Check out your most frequently used commands on Linux

In Linux, the history file ~/.bash_history keeps track of all the commands you type in the terminal, so we can use this file to find the commands you use most often.

This is done as follows:

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

The results of the above command will show the five most frequently used commands on Linux.

The output is as follows:

153 sudo118 ls33 cd30 ssh39 git

This result is very refreshing and intuitive!

So, do you know what each part of the above command does? Now, let's go into 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 what you see on Ubuntu, but on other platforms, like CentOS, you see a different situation, and the corresponding commands need to be slightly changed.

awk '{print $2}' Print column 2 string from history file without displaying command options and parameters

sort Sort all rows alphabetically

uniq -c removes duplicate rows and counts them

sort -nr sort backwards according to statistics returned by uniq command

Tip: You can use Explain Shell to find a description of what each option in the command does.

As you can see from the results, sudo is the most frequently used command by the current user, used 153 times.

The results are displayed in descending order. If you want them 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 to the previous command to see the 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 command above.

$ history | awk '{print $2}' | sort | uniq -c |sort -nr Above is "How to view your own most frequently used commands on Linux" All of the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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