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

Common commands in Linux

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

Share

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

Do you know which commands you use most often? Today let's take a look at the commands we use most frequently when using Linux.

I don't know what commands you have used since you came into contact with Linux, and what is the most commonly used command?

One of my most common commands is sudo, because I use it every day to install, update, remove packages, and various other operations that require superuser privileges on Linux.

So which commands do you know you use most often? Today let's take a look at the commands we use most frequently when using 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, does not show command options and parameters sort alphabetically arranges all lines uniq-c delete duplicate lines and carries on count statistics sort-nr reverse sort tips according to the statistics returned by the uniq command: you can use Explain Shell to find the 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

Original address: https://www.linuxprobe.com/linux-general-commands.html

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