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 most frequently used commands under Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article analyzes "how to view the most commonly used commands in Linux". The content is detailed and easy to understand. Friends who are interested in "how to check the most frequently used commands under Linux" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's follow the editor to learn more about "how to view the most commonly used commands in Linux".

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 ExplainShell 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

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

On how to view the most commonly used commands under Linux to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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

Development

Wechat

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

12
Report