Linux Commands that Newbies Must Know

    This article will further learn the linux commands that must be mastered, and master these commands to make the computer understand you better.

    As far as the centos operating system we have installed above is concerned, we usually operate in two ways: the first is to operate graphically through the desktop; the other is to enter commands through the terminal.

    For the server, we usually use a remote connection tool to connect to the server, and then manage it by command. How does a computer know what to do when we type a command? Then you have to rely on command line tools (also called terminals) to translate and interpret, and then call the corresponding interface services to complete specific functions.

The interaction between the user and the linux system is through the shell terminal. The following section will first analyze the shell command line tools, and then explain the most basic linux commands.

1. Introduction to shell

    Computer hardware is composed of arithmetic unit, controller, memory, input/output devices, etc., and the thing that allows various hardware devices to perform their own functions and work together is the system kernel. The kernel of the Linux system is responsible for completing management tasks such as allocation and scheduling of hardware resources. Therefore, the system kernel is very important to the normal operation of the computer. Generally, it is not recommended to edit the parameters in the kernel directly, but to allow users to manage the computer through programs or services developed based on the system call interface to meet the needs of daily work. The shell is such a client-side command-line tool that acts as a bridge between the user and the system kernel.

    Shell, also known as "terminal" and "shell", is a command-line tool written in C language, acting as a translator between humans and the kernel (hardware). The user "tells" some commands to the terminal, and it will call the corresponding command. The program service to do some work.

1.1 shell version

    Listed below are several shell versions

  • sh (Bourne Shell): It is the shell originally used by UNIX and can be used on every UNIX. Great at shell programming, but not as good at handling interaction with the user as several other shells.
  • bash (Bourne Again Shell): Linux default, is an extension of Bourne Shell. It is fully compatible with Bourne Shell, and adds many features such as command completion, command history, etc. It also contains many advantages of C Shell and Korn Shell, has flexible and powerful editing interface, and has a very friendly user interface.
  • csh (C Shell): A more suitable variant of the Bourne Shell, the syntax is very similar to the C language.
  • Tcsh: An extended version of the C Shell provided by Linux. Including command line editing, programmable word completion, spell correction, historical command substitution, job control and C-like syntax, it is not only compatible with the Bash Shell prompt, but also provides more prompt parameters than the Bash Shell.
  • ksh (Korn Shell): It combines the advantages of C Shell and Bourne Shell and is fully compatible with Bourne Shell.
  • pdksh: An extension to ksh provided by Linux systems. Support character control, you can suspend on the command line, execute in the background, wake up or terminate the program.

    The default terminal used by many mainstream Linux systems, including Red Hat, is the Bash (Bourne-Again SHell) interpreter. The mainstream Linux system chooses the Bash interpreter as the command line terminal mainly because of the following four advantages:

    The installed centos7 also uses the bash terminal by default. When using a remote connection tool to connect to centos7, the default open terminal is bash, which can be viewed by entering the command in the terminal: echo $SHELL, and the result is: /bin/ bash.

  • How to judge the type of the current terminal?

​ via "echo $SHELL" command or via "evn" terminal command

  • How do I change the terminal type I log in to?

​ Use the terminal command chsh, such as: chsh -s /bin/bash to change the login terminal to bash

1.2 Shell Command Types

    A shell is a program that is used by the user to interact with the operating system, and is equivalent to a command parser.

    As an interface between the user and the kernel, it is both a command language and a programming language. Shell commands are further divided into built-in commands and external commands.

  • built-in commands

The internal command is actually a part of the shell program, which contains some relatively simple linux system commands. These commands are recognized by the shell program and run inside the shell program. Usually , the shell is loaded and resident when the linux system loads and runs. in system memory . Internal commands are written in the bashy source code, and their execution speed is faster than external commands, because parsing the internal command shell does not require the creation of subprocesses. For example: exit, history, cd, echo, etc.

  • external command

The external command is the utility part of the linux system. Because the function of the utility program is usually relatively powerful, the amount of programs it contains will also be large . only when it is called into memory . Usually the entity of the external command is not contained in the shell, but its command execution process is controlled by the shell program . The shell program manages the path search, loading and storage of external command execution, and controls the execution of commands. External commands are installed outside of bash, usually in /bin, /usr/bin, /sbin, /usr/sbin...etc. You can view the storage path of external commands through the "echo $PATH" command, such as: ls, vi, etc.

How to distinguish whether it is an internal command or an external command?

  1. Through the type command, such as: type cd can see that it is an internal command; type mkdir can see that it is an external command.
  2. Through the man command, such as: man cd, it will prompt that it is a built-in command of bash; man ls, it will prompt that it is an external command.

    The biggest difference between internal commands and external commands is performance. Internal commands execute much faster than external commands because they are built into the shell and do not have to create extra processes. So just like executing a larger script, executing a script that contains many external commands can hurt the performance of the script.

The most commonly used commands

    Now that there is already a "translator" such as Bash in the Linux system, it is necessary to learn how to communicate with it. In order to complete various tasks accurately and efficiently, it is not enough to rely only on the command itself, and the parameters of various commands should be flexibly adjusted according to the actual situation.

The general format of linux execution command: command name [command parameter] [command object]

    Separate command names, command parameters, and command objects with a space bar. Command objects generally refer to files, directories, users and other resources to be processed, and command parameters can be in long format (--) or short format (-).

Long form: man --help

Short form: man -h

    There are many linux commands, and the most important thing is the combination of various parameters. It is impossible for a novice to remember all the parameters, and it is necessary to check them frequently through the help command.

Special note: In the terminal, sometimes a lot of content is displayed, and you can browse through the shortcut keys.

shift PgUp: page up

shift PgDn: page down

2.1 Help commands

    There are two main help commands: man and help. Usually, there are more help commands. If you encounter an unclear command, use the help command to check it. You don't need to memorize it by rote, and practice makes perfect.

2.1.1 man command
Syntax: man [command or configuration file]

Function: Get help information


[root@heimatengyun ~]# man date

    For example, if you want to view the usage of the date command, after entering the command man date, the following information will appear


    Since there is a lot of help information, you need to turn the page to read it, so first explain that this interface may need to use the keys and their purposes.



space bar

page down

PgDn (page down)

page down

PgUp (page up)

page up


Go to homepage


go to footer


Search keywords from top to bottom, such as "/linux"


Search keywords from the bottom up, such as "?linux"


Locate the next searched keyword


Locate the last searched keyword


Exit the help file

    When a beginner looks at it, so much help information is confusing. In fact, it is very simple. Let's take a look at the structure of the help information (the part circled with the red line in the above figure).

structure name



the name of the command


Basic syntax of commands


Explain in detail the usage of options and parameters corresponding to the syntax format


Example of how to use the command




Default function


specific options available


environment variable


Relevant information, usually man pages

    Through these help information, you can easily grasp the usage of each command.

2.1.2 help command
Syntax: help command

Role: Get help information for shell built-in commands


[root@heimatengyun ~]# help cd

Before officially entering the command learning, let 's introduce a few common shortcut keys in linux

hot key


ctrl l

clear screen

ctrl q


ctrl c

stop process

Up and down keys

Find commands executed in the past


Command completion, multi-purpose not only improves efficiency but also prevents typing mistakes

    Since everything in linux is a file, after understanding the omnipotent help command, we will start learning from the directory file command.


2.2 Directory related commands

    The directory can classify and manage files, so the directory-related commands are explained before the file commands are explained.

2.2.1 pwd
Syntax: pwd

Function description: Display the absolute path of the current working directory


[root@heimatengyun ~]# pwd

2.2.2 ls
Syntax: ls [options] [directory or file]

Function description: List the files in the directory


​ -a(--all): show all files, including hidden files (files starting with .)


​ -l: long long data string list, including file attributes and permissions, etc. The information listed on each line is: file type and permissions, number of links, file attributes, file group, file size (byte), creation or last modification time, name


[root@heimatengyun test]# ls -al
total 12
drwxr-xr-x.  2 root root   37 Nov 24 10:43 
.dr-xr-x---. 16 root root 4096 Nov 24 00:02 
..-rw-r--r--.  1 root root   26 Nov 23 20:40 
test1.txt-rw-r--r--.  1 root root   66 Nov 23 21:56 test.txt
2.2.3 cd
grammar:cd [option][dir name]

Function description: switch to the specified directory


​ cd absolute path or relative path (jump to the specified directory)

​ cd or cd ~ (returns the current user home directory)

​ cd - (return to the last directory)

​ cd .. (return to the previous directory of the current directory)
2.2.4 mkdir
Syntax: mkdir [options] directory name

Function description: Create the specified directory


​ -p : parents, create multi-level directories


​ [root@heimatengyun ~]# mkdir test

​ [root@heimatengyun ~]# mkdir -p test1/test1
2.2.5 is rm
Syntax: rmdir [options] directory name

Function description: delete empty directory


​ -p: delete multi-level directories


​ [root@heimatengyun ~]# rmdir test

​ [root@heimatengyun ~]# rmdir -p test1/test1/ (If the -p parameter is not specified, only the directory whose last level is not empty will be deleted)
2.2.6 cp
Syntax: cp source directory or file target directory or file

Function description: copy directory or file


​ -r: recursive, recursively copy the entire folder


Copy test as test.txt, rename it when copying

[root@heimatengyun ~]# cp test test.txt

Copy all test directory contents to test1 directory (automatically create test1 directory)

[root@heimatengyun ~]# cp -r test test1  
2.2.7 mv
Syntax: mv [options] source target

Function description: move files or rename files


Rename the test file to test.txt

[root@heimatengyun test]# mv test test.txt   

Move the test directory and all its contents to the test2 directory, and automatically create the test2 directory (it can be understood as renaming the test folder to test2)

[root@heimatengyun ~]# mv test/ test2  
2.2.8 rm
Syntax: rm [options] file

Function description: delete files and directories


​ -f: force to enforce

​ -r: recursive recursive execution


Recursively delete a directory and everything under it

 [root@heimatengyun ~]# rm -rf test2/  

2.3 File related commands

    Everything in linux is a file. After connecting the directory-related commands, this section learns the file-related commands.

2.3.1 touch
Syntax: touch [options] filename

Function description: Create empty file


 [root@heimatengyun test]# touch test.txt


Syntax: echo string or variable

Function description: output string or variable value, and can also store content to file with slave directional character


[root@heimatengyun test]# echo hello


[root@heimatengyun test]# echo $SHELL


[root@heimatengyun test]# echo linux >> test.txt
2.3.2 cat
Syntax: cat [options] filename

Function description: View the content of the file, starting from the first line


​ -A: List special characters instead of whitespace

​ -b: List line numbers, blank lines are not counted as line numbers

​ -n: List line numbers, blank lines will also have line numbers

​ -v: List some invisible special characters


 [root@heimatengyun test]# cat test.txt


 who are you

 where are you from

 [root@heimatengyun test]# cat -A test.txt


 who are you$


 where are you from$

 [root@heimatengyun test]# cat -b test.txt

      1  hello

      2  who are you

      3  where are you from

 [root@heimatengyun test]# cat -n test.txt

      1  hello

      2  who are you


      4  where are you from
2.3.3 more
Syntax: more [options] file

Function description: View file content, display page by page

Instructions for use:

​ Space bar (space): page down

​ enter: scroll down a line

​ q: Exit more, no longer display file content

​ ctrl f: scroll down one screen

​ ctrl b: return to the previous screen

​=: output the line number of the current line

​ :f: output file name and current line number
2.3.4 head
Syntax: head [options] file

Function description: View the content of the file, only the first few lines


​ -n: view the first n lines


​ [root@heimatengyun test]# head -n 2 test.txt
2.3.5 tail
Syntax: tail [options] file

Function description: View the content of the file, only the last few lines of the file


​ -n: last few lines

​ -f: follow the content of output file modifications, used to track file modifications


​ [root@heimatengyun test]# tail -n 2 test.txt
2.3.6 wc
Syntax: wc [options] text

Function description: Count the number of lines, words and bytes of the specified text


​ -l: lines display the number of lines

​ -w: display the number of words

​ -c: display the number of bytes


[root@heimatengyun test]# cat test.txt 
hellowho are youwhere are you form?wellcomehahahtest

[root@heimatengyun test]# wc -l test.txt 

8 test.txt[root@heimatengyun test]# wc -c test.txt 

60 test.txt[root@heimatengyun test]# wc -w test.txt 

11 test.txt
2.3.7 stat
Syntax: stat [options] file

Function description: View the specific storage information and time of the file


[root@heimatengyun test]# stat test.txt

    File: ‘test.txt’

    Size: 60              Blocks: 8          IO Block: 4096   regular file

  Device: fd01h/64769d    Inode: 2160373     Links: 1

  Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

  Context: unconfined_u:object_r:admin_home_t:s0

  Access: 2019-11-23 18:27:02.153101936  0800

  Modify: 2019-11-23 18:26:56.254259870  0800

  Change: 2019-11-23 18:26:56.254259870  0800

   Birth: -
2.3.8 cut
Syntax: cut [options] file

Function description: Extract text characters by column


​ -d: delimiter separator

​ -f: fields column to extract


Query all user names in the system

[root@heimatengyun test]# cut -d: -f1 /etc/passwd






2.3.9 diff
Syntax: diff [options] file1, file2

Function description: Compare the differences of multiple texts


​ --brief: show whether the compared files are the same

​ -c: context tag displays different content
2.3.10 dd
Syntax: dd [parameter or option]

Function description: Copy files or convert files according to the specified size or number of databases


​ if: the input file name

​of: output file name

​ count: Set the number of blocks to be copied

​ bs: bytes file block size


Create a file with a specified size of 10M

[root@heimatengyun test]# dd if=/dev/zero of=10_file count=1 bs=10M1 0 records in1 0 records out10485760 bytes (10 MB) copied, 0.0102506 s, 1.0 GB/s

[root@heimatengyun test]# ll

total 10248

-rw-r--r--. 1 root root 10485760 Nov 23 21:05 10_file
2.3.11 file
Syntax: file filename

Function description: View file type


[root@heimatengyun test]# file test.txt test.txt: ASCII text
2.3.12 wget
Syntax: wget [parameter] [url address]

Function: download network files


​ -b: background background download

​ -P: directory-prefix download to the specified directory

​ -t: tries maximum number of attempts

​ -c: continue the breakpoint resume

​ -p: page-requisites Download all content of the page, including pictures, videos, etc.

​ -r: recursive recursive download


Download Baidu logo image

[root@heimatengyun test]# wget

--2019-11-23 22:29:45--

Resolving (,

Connecting to (||:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 7877 (7.7K) [image/png]

Saving to: ‘bd_logo1.png’100%[======================>] 7,877       --.-K/s   in 0.002s  2019-11-23 22:29:45 (4.43 MB/s) - ‘bd_logo1.png’ saved [7877/7877]

2.4 Find command

    Sometimes you need to find the required file from a large number of files or find specific content from a specified file, which requires the use of search-related commands.

2.4.1 find
Syntax: find [search scope] [match condition]

Function description: Find a file or directory

Parameter Description

​ -name: Find by file name

​ -user: find by file owner

​-size: root find files by file size (n is greater than, -n is less than, n is equal to)


Find the test1.txt file in the test directory

[root@heimatengyun ~]# find test/ -name test1.txttest/test1.txt

Find the file in the test directory to find the user root

[root@heimatengyun ~]# find test/ -user roottest/test/test.txt

Find files smaller than 100M in the test directory

[root@heimatengyun ~]# find test/ -size -102400test/test/test.txt
2.4.2 grasp
Syntax: grep [parameters] Find content source files

Function description: Search the file for the line matching the string and output


​ -c:count only output the count of matching lines

​ -n: line-number Display matching lines and line numbers


[root@heimatengyun test]# grep -n who test.txt 

3:who are you[root@heimatengyun test]# grep -c who test.txt 

2.4.3 which
Syntax: which [options] command

Function description: Search command directory and alias information


Search the directory where the cd command is located

[root@heimatengyun test]# which cd


2.5 Compression and decompression

    In order to facilitate transmission or save storage space, sometimes files exist in the form of compressed packages, so it is necessary to understand the commands related to compression and decompression.

2.5.1 takes
Syntax: tar [parameter] package name.tar.gz content to be packaged

Function description: package directory, the compressed file format is .tar.gz


​ -c: create generates a .tar package file

​ -x: extract unpacks the .tar file

​ -v: verbose show detailed information

​ -f: file specifies the compressed file name

​ -z: pack and compress at the same time

​ -C: Unzip to the specified directory


Compress multiple files, compress test.txt and test1.txt into test.tar.gz

[root@heimatengyun test]# tar -zcvf test.tar.gz test.txt test1.txt test.txttest1.txt[root@heimatengyun test]# lltotal 10252-rw-r--r--. 1 root root       26 Nov 23 20:40 test1.txt-rw-r--r--. 1 root root      210 Nov 23 23:57 test.tar.gz-rw-r--r--. 1 root root       66 Nov 23 21:56 test.txt

zip directory

[root@heimatengyun ~]# tar -zcvf test.tar.gz test/

Unzip to current directory

[root@heimatengyun test]# tar -zxvf test.tar.gz 
2.5.2 zip and unzip

​ Compression: zip [parameter] package Content to be compressed

​ Unzip: uzip package

Function description: Compress files and directories, common to windows and linux, and can compress directories and retain source files


​ -r: recurse-paths recursively compress directories


Compress test.txt or test1.txt to

[root@heimatengyun test]# zip test.txt test1.txt 

  adding: test.txt (deflated 15%)

  adding: test1.txt (stored 0%)


[root@heimatengyun test]# unzip Archive:

  inflating: test.txt                

 extracting: test1.txt  
2.5.3 gzip and gunzip

​ Compression: gzip [parameter] file

​ Unzip: gzip [parameter] file.gz

Function description:

​ Compression: Compress the file, you can only compress the file into a *.gz file. You can only compress files but not directories, and the original files are not retained after compression and decompression. Compress a single file

​ Unzip: Unzip the file

​ Case:

Compressed file

[root@heimatengyun test]# lltotal 8-rw-r--r--. 1 root root 26 Nov 23 20:40 test1.txt-rw-r--r--. 1 root root 66 Nov 23 21:56 test.txt[root@heimatengyun test]# gzip test1.txt [root@heimatengyun test]# lltotal 8-rw-r--r--. 1 root root 54 Nov 23 20:40 test1.txt.gz-rw-r--r--. 1 root root 66 Nov 23 21:56 test.txt

unzip files

[root@heimatengyun test]# lltotal 8-rw-r--r--. 1 root root 54 Nov 23 20:40 test1.txt.gz-rw-r--r--. 1 root root 66 Nov 23 21:56 test.txt[root@heimatengyun test]# gunzip test1.txt.gz [root@heimatengyun test]# lltotal 8-rw-r--r--. 1 root root 26 Nov 23 20:40 test1.txt-rw-r--r--. 1 root root 66 Nov 23 21:56 test.txt

2.6 Date command

    Date related commands are used to set or get the system date.

2.6.1 date
Syntax: date [options] [format]

Function description: display or set the time


​ -s: set set the time in string format

Format: (note case sensitivity)

​ %Y: Display the current year

​ %m: Display the current month

​ %d: Displays the current day

​ %H: Display the current hour

​ %M: Display the current minute

​ %S: Display the current number of seconds

​ %Y%m%d: Display the current year, month and day

​ " %Y-%m-%d %H:%M:%S": Display the current year, month, day, hour, minute and second (enclosed in quotation marks)


set time

[root@heimatengyun test]# date -s "2019-11-24 11:05:10"Sun Nov 24 11:05:10 CST 2019

display time

[root@heimatengyun test]# dateSun Nov 24 11:02:21 CST 2019[root@heimatengyun test]# date  %Y%m%d

20191124[root@heimatengyun test]# date " %Y-%m-%d %H:%M:%S"

2019-11-24 11:02:55

    date to view non-current time (such as the previous day, the next day, take the next week Monday, etc.) and cal to view the calendar command will not be discussed for the time being, and there will be a chance to discuss it later.

2.7 Process thread commands

    Tasks exist in the form of processes or threads, so you need to keep an eye on system processes at any time, check whether there are abnormal processes and how each process occupies system resources, and use different process management commands to manage and control processes.

2.7.1 ps
Syntax: ps [options]

Function description: View all processes in the system


​ -a: all displays all programs under the current terminal, including programs of other users (for example, multiple clones of several sessions to execute different commands will also be listed)

​ -u: userlist Display program status in user-based format

​ -x: Display all programs, not differentiated by terminals (as mentioned earlier, there are many types of terminals, not only the current terminal)


[root@heimatengyun test]# ps -aux


root       2966  0.0  0.1 116340  3192 pts/0    Ss   Nov22   0:03 -bash


Explanation of each item




which user the process was created by


Process ID


The percentage of CPU occupied by the process. The higher the occupancy, the more resource-consuming the process.


The percentage of memory occupied by the process. The higher the occupancy, the more resources the process consumes.


The size of virtual memory occupied, in KB


The size of the actual physical memory occupied, in KB


Indicates which terminal the process is running in, tty1-tty7 represents the local console terminal (tty1-tty6 is the local character interface terminal, tty7 is the graphic terminal), pts/0-255 represents the virtual terminal


Process state, common states are: R (running), S (sleep), T (stop state), s (including child processes), (in the background)


Process start time


Process execution time, that is, the computing time occupied by the CPU, not the system time


The name of the command that spawned this process

2.7.2 top
Syntax: top [options]

Function description: View system health status


​ -d seconds: Delay-time, specify the top command to update every few seconds, the default is 3 seconds.

​ -i: Idle-process, so that the top command does not show any idle or zombie processes

​ -p: Monitor-PIDs, only monitor the status of a process by specifying the monitoring process ID

​ -s: Secure-mode, make top run in safe mode and remove potential dangers caused by interactive commands


View non-zombie processes, refresh once a second

[root@heimatengyun test]# top -i -d 1

top - 12:39:19 up 1 day, 14:31,  3 users,  load average: 0.04, 0.04, 0.05Tasks: 395 total,   1 running, 391 sleeping,   3 stopped,   0 zombie

%Cpu(s):  0.0 us,  1.0 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 stKiB Mem:   1870784 total,   720520 used,  1150264 free,      880 buffersKiB Swap:  2097148 total,        0 used,  2097148 free.   238616 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME  COMMAND              

 29987 root      20   0  123936   1868   1160 R   2.0  0.1   0:08.32 top 


In this interface, you can use the following corresponding keys to sort operations

Action keys


shift n

Sort by PID

shift m

Sort by memory

shift p

Sort by cpu usage, default option


exit top

Interpretation of command results

The first line: task queue information




current system time

up 1 day, 14:12

system uptime

3 users

Number of currently logged in users

load average: 0.08,0.01, 0.05

The average load of the system in the previous 1 minute, 5 minutes, and 15 minutes is generally considered to be less than 1, the load is small, if it is greater than 1, the system has exceeded the load

The second line: process information



Tasks: 395 total

The total number of processes in the system

1 running

Number of running processes

391 sleeping

sleeping process

3 stopped

stopping process

0 zombie

Zombie process, if not 0, you need to manually check the zombie process

The third line: cpu information



%Cpu(s): 0.0 us

CPU percentage used in user mode

1.0 and

CPU percentage used in system mode

It is 0.0

Percentage of CPU occupied by user processes whose priority has been changed

99.0 id

percentage of idle cpu

0.0 of

Percentage of CPU occupied by processes waiting for input and output

0.0 hi

Percentage of CPU occupied by hard interrupt request service

0.0 and

Percentage of CPU occupied by softirq request service

0.0 st

steal time virtual world percentage, when there is a virtual machine, the percentage of time that the virtual cpu waits for the timing cpu

ps: if the server has multiple cpus, multiple lines will be displayed

Fourth line: physical memory information



KiB Mem: 1870784 total

The total amount of physical memory, in KB

720520 used

Amount of physical memory used

1150264 free

Amount of free physical memory

880 buffers

Amount of memory as buffer

Fifth line: swap partition information



KiB Swap: 2097148 total

Total size of swap partition (virtual memory)

0 used

The size of the used swap partition

2097148 free

The size of the free swap partition

238616 cached Mem

The size of the swap partition used as cache

Sixth line: blank line

The seventh line: header information




process id


process owner


Process priority


Negative values ​​indicate high priority, positive values ​​indicate low priority


The total amount of virtual memory used by the process, in kb. VIRT=SWAP RES


The size of the physical memory used by the process but not swapped out, in kb. RES=CODE DATA


Shared memory size, in kb


Process status. D=uninterruptible sleep state R=running S=sleep T=track/stop Z=zombie process


The percentage of CPU time used since the last update


The percentage of physical memory used by the process


The total CPU time used by the process, in 1/100th of a second


Process name (command name/command line)

2.7.3 pidof
Syntax: pidof [parameter] service name

Function description: Query the pid value of a specified service process


View the process id of the sshd service

[root@heimatengyun test]# pidof sshd

2962 2247
2.7.4 pstree
Syntax: pstree [options]

Function description: View process tree


​ -p: Display the PID of the process


[root@heimatengyun test]# pstree -p


           │                   └─{ModemManager}(1031)


           │                      └─{NetworkManager}(1312)

2.7.5 kill
Syntax: kill [options] process id

Function description: Terminate a service process with a specified pid


​ -9: Force the process to stop immediately


[root@heimatengyun test]# kill -9 20385
2.7.6 killall
Syntax: killall [options] service name

Function description: Terminate all processes corresponding to a service with a specified name


Terminate all processes of the httpd service

[root@heimatengyun test]# killall httpd

2.8 System Status Detection Command

    Use related commands to check the system status and resource consumption to ensure the healthy and stable operation of the system.

2.8.1 ifconfig
Syntax: ifconfig [network device] [parameters]

Function description: Get network card configuration and network status information


[root@heimatengyun test]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet  netmask  broadcast

        inet6 fe80::20c:29ff:febc:5eef  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:bc:5e:ef  txqueuelen 1000  (Ethernet)

        RX packets 143336  bytes 103106029 (98.3 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 92576  bytes 143399144 (136.7 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Main view content: network card name (eno16777736), ip address (after inet), physical network card address, ie mac address (ether), number of packets received and sent by TX and TX, and cumulative traffic
2.8.2 netstat
Syntax: netstat [parameters]

Function description: Display the current network status of the entire system, such as current links, data packet transmission data, routing table content, etc.


[root@heimatengyun test]# netstat

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State      

tcp        0     96      ESTABLISHED

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags       Type       State         I-Node   Path

unix  2      [ ]         DGRAM                    13149    /run/systemd/shutdownd

2.8.3 uname
Syntax: uname [options]

Function description: View information such as system kernel and system version


​ -a:all Display complete system information

​ -s: kernel-name system kernel name

​ -n: nodename node name

​ -r: kernel-release kernel release

​ -v: kernel-version kernel version

​ -m: machine hardware name

​ -i: hardware-platform hardware platform

​ -p: processor processor type

​ -o: operating-system operating system name


[root@heimatengyun test]# uname


[root@heimatengyun test]# uname -a

Linux heimatengyun 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The displayed information is: kernel name (Linux), host name (heimatengyun), kernel release (3.10.0-123.el7.x86 64), kernel version (#1 SMP Mon Jun 30 12:09:22 UTC 2014) , hardware name (x86 64), hardware platform (x86 64), processor type (x86 64), and operating system name (GNU/Linux).

If you want to view the details of the single-signature system version, by viewing the /etc/redhat-release file

[root@heimatengyun test]# cat /etc/redhat-release

CentOS Linux release 7.0.1406 (Core)
2.8.4 uptime
Syntax: uptime [options]

Function description: View the load information of the system, which can display information such as the current system time, the system running time, the number of enabled terminals, and the average load value. The average load value refers to the pressure of the system in the last 1 minute, 5 minutes, and 15 minutes. The lower the load value, the better, try not to exceed 1 for a long time, and do not exceed 5 in the production environment.


[root@heimatengyun test]# uptime

 21:30:44 up 1 day, 23:23,  3 users,  load average: 0.00, 0.01, 0.05
2.8.5 free
Syntax: free [options]

Function description: Display the memory usage information in the current system


​ -m: megabytes display in megabytes

​ -h: human with unit output


[root@heimatengyun test]# free -h

total       used       free     shared    buffers     cachedMem:         
 1.8G       702M       1.1G       8.9M       880K       233M

-/  buffers/cache:       468M       1.3GSwap:         2.0G         0B       2.0G

Field description: total (total memory), used (used), free (available), shared (memory shared by processes), buffers (disk cached memory), cached (cached memory)
2.8.5 who
Syntax: who [parameter]

Function description: View the user terminal information currently logged into the host


[root@heimatengyun test]# who

root     pts/0        2019-11-22 22:10 (

root     pts/1        2019-11-23 11:53 (
2.8.6 last
Syntax: last [parameter]

Function description: View all system login records. However, it should be noted that this information is saved in log files, so hackers can easily modify it, so this command cannot be used to judge whether there is hacking.


[root@heimatengyun test]# last

root     pts/2     Sun Nov 24 13:09 - 13:36  (00:26)

root     pts/1     Sat Nov 23 11:53   still logged in 

2.8.7 history
Syntax: history [parameters]

Function description: Display the commands executed in history


​ -c: Clear all history, but .bash_history file contents will not be deleted


[root@heimatengyun test]# history

    1  history

    2  ll

    3  ls

    4  history

[root@heimatengyun test]# !2


total 8

-rw-r--r--. 1 root root 26 Nov 23 20:40 test1.txt

-rw-r--r--. 1 root root 66 Nov 23 21:56 test.txt

You can use "!Number" to execute a command that has been executed once

1000 historical records can be viewed by default, but the value of HISTSIZE can be modified in /etc/profile

History commands are saved in a .bash_history file in a farmer's home directory (hidden files at the beginning of . are listed through ls or ll -a), which can be viewed with the cat command

2.9 Shutdown command

    Linux is generally used on servers, and rarely encounters shutdowns. After all, the shutdown service will be interrupted, and it will be shut down unless there are special circumstances.

Correct shutdown process: sync>shutdown or reboot or halt

Regardless of restart or shutdown, you need to sync the memory data to the hard disk first to avoid data loss

2.9.1 reboot
Syntax: reboot [options]

Function description: Restart the system, equivalent to shutdown -r now


[root@heimatengyun ~]# reboot
2.9.2 poweroff
Syntax: poweroff [options]

Function description: Shut down the system


[root@heimatengyun ~]# poweroff
2.9.3 halt
Syntax: halt [options]

Function description: Shut down the system, equivalent to shutdown -h now and poweroff


[root@heimatengyun ~]# halt
2.9.4 shutdown
Syntax: shutdown [options] [shutdown time] [prompt content]

Function description: shutdown


​ -h: shutdown

​ -r: restart

Shutdown time:

​ hh:mm: Specifies the hour and minute in 24-hour clock to shut down

​ m: shutdown after m minutes (1: default, shutdown after 1 minute; 0: now, shutdown immediately)


Shut down after 1 minute and prompt all users logged into the system

[root@heimatengyun ~]# shutdown -h 1 "this server will shutdown after 1min"this server will shutdown after 1min

The system is going down for power-off at Sun 2019-11-24 22:25:55 CST!

User and file-related permission commands will be explained in future articles, and there are many other commands, which are not discussed here due to space limitations. The next article article will share "linux introductory series 6--rpm and yum repository for package management".


Original article, please indicate the source for reprinting: