At the beginning of the article, I recommend a website for querying Linux commands. If you don’t understand the English document of man command, you can go to this website. Click here to introduce the following command in order to avoid too much space, will not show all parameters, you can also go to this website process detailed query.
Tips: This article is too long, you can Ctrl+F query the command you want
Man: Help command
Example: man ps
This command displays a detailed description of the ps command. The following figure shows common cases and instructions in the MAN command.
Echo: output
Example 1: Echo Hello Linux
This command prints Hello Linux.
Example 2: echo $SHELL
$fetches the value of the variable, which prints the value of the variable SHELL.
Date: time
Format: date [option] [Specify output format]
Example 1: Date
The current system time is displayed in the default format.
Example 2: date “+%Y-%m-%d %H:% m :%S”
The current system time is displayed in the specified format, for example, 2020-09-20 12:15:38
The following figure shows the parameters of the date command and their effects
Reboot: restart
This command is used to restart the system, which can only be restarted by the root user by default.
Poweroff: Shuts down the system
This command is used to shut down the system, which can only be shut down by root by default.
Wget: download
The wege command is used to download network files from the terminal. The format is wget [Parameter] Download address
Example: the wget HTTP: / / http://localhost/test.txt
The following figure shows the parameters and functions of the wget command
Ps: View the process status
The ps command is used to check the status of processes in the system.
Example: PS -A
The above command displays all processes. The following figure shows the parameters and functions of the ps command.
Top: Task manager
The top command dynamically monitors process activity and system liability information, which is equivalent to the Task manager in Windows.
The top command is very simple to use and requires no additional arguments, but you need to understand the information inside. Here is an example of what the following rows and columns mean.
The first line: system time, running time, number of terminals logged in, and system load (the three values represent the average values of 1 minute, 5 minutes, and 15 minutes respectively. A smaller value indicates a lower load).
Second line: total number of processes, number of running processes, number of sleeping processes, number of stopped processes, number of dead processes.
The third line: the first line represents the percentage of resources occupied by the user and the second system kernel.
The fourth and fifth lines represent information about physical and virtual memory, respectively.
Pidof: Queries the PID of a specified process
The format for this command is pidof [parameter] [service name]
Example: pidof SSHD
This command displays the PID of the SSHD process.
Kill: Terminates a process
The format is kill [parameter] [process PID].
Example: kill 666
Terminates the process whose PID is 666.
Killall: terminates all processes of a service
Killall can be used in complex programs where multiple processes provide services at the same time. It is difficult to killall processes in the program one by one
Example: killall HTTPD
Ifconfig: Displays the network configuration and information
The command displays network information such as the name, IP address, and MAC address of the local NETWORK adapter.
Uanme: View the system kernel and version information
Example: uname -a
This command displays the kernel name, host name, release, system time, and so on.
Uptime: displays the system load information
This command displays the current system time, running time, number of terminals started, and load average (1 minute, 5 minutes, and 15 minutes).
Free: View memory information
Example: free-h
This command displays real-time memory usage information.
Who: specifies the information about the current login user
This command displays the names of all users who are logging in to the machine and the information about the terminals they have opened.
Last: View system login records
This command allows you to view login records on the host.
History: displays executed commands
After displaying the command record, we can use the “! Line number number “to execute a command repeatedly.
Sosreport: Collects system information and outputs diagnostic documents
PWD: Displays the working directory of the current user
CD: Switch the working path
This command is probably one of the most commonly used. In addition to using the absolute path directly, you can also use some shortcuts to switch.
Example 1: CD – Return to the previous directory
Example 2: CD ~ Switch to the home directory
Example 3: CD.. Return to parent directory
Ls: displays information about files in a directory
Format: ls [parameter] [file]
Example: ls-al
-a displays all files, including hidden files. -l Displays details.
Cat: View plain text file (less content)
Example: cat-n readme.txt
-n Displays the line number
More: View a plain text file (with many contents)
Example: more readme.txt
Head: view the first N lines of the text
Example: head -n 20 readme.txt
-n 20 indicates the first 20 rows.
Tail: View the N lines after the text
Example: tail -n 20 -f readme.txt
-n 20 indicates the next 20 lines. -f will refresh the file continuously, meaning that we will see the text change in time.
Tr: Replaces characters in text
Use format: tr [original character] [target character]
Example: the cat readme. TXT | tr [a-z] [a-z]
This instruction is used in the pipe ‘|’, its role is to put the front behind the output of an instruction as an instruction input. So the whole idea is to change the lowercase letters in readme.txt to uppercase letters.
Wc: indicates statistics text information
The wc command is used to count the number of lines, words, and bytes of the specified text in the following format: wc [parameter] [Specified text]
Its parameters are shown in the following figure
Example: wc -l readme.txt
Stat: Displays file storage information
Example: stat readme.txt
Cut: Displays the specified part of the line
Example: cut -d: -f1 readme.txt
Query the first row with colon intervals
Diff: Compares the differences between multiple texts
Example: diff -q -c readme1.txt readme2.txt
Shows the differences between README1 and readme2.
Touch: Creates a blank file
This command is used to create a blank file or to set the time of the file. Format: touch [parameters] [file]
If you want to create a file, it’s very simple, just touch [filename]
To change the file time, use the following parameters
Example: touch -d “2020-09-20 20:20:20” readme.txt
Mkdir: creates an empty directory
Example: mkdir -p newDir/myDir
-p Is used to recursively create directories.
Cp: copies directories or files
The following figure shows common commands
Example: cp readme1.txt /etc/readmecopy.txt
Mv: cuts or renames the file
If the clipped directory does not change, rename it.
Example: mv readme.txt newname.txt
Rm: Deletes a file or directory
Example: rm readme.txt
Dd: copies files according to the specified size and number
The following figure shows common parameters
Example: dd if=/dev/zero of=newFile count=1 bs=560M
The effect of this command should be clear, with the block size set to 560M and the number set to 1.
File: View the file type
Example: file readme.txt
Tar: decompresses the file
The following figure shows common parameters.
Example: tar -czvf et.tar. gz /etc
Zip the directory to /etc/tar.gz. These four parameters are abbreviated, but note that -f must come last.
Grep: Searches text for keywords
This command is often used. The parameters are shown in the following figure.
Example: grep word readme.txt
Search the word word in readme.txt. If we replace grep with grepE, the searched words can be written as regular expressions.
Find: Searches for files based on the specified criteria
The following figure shows common parameters.
Example: find /etc/name “host*” -print
Display files starting with host in /etc.
Useradd: Creates a user
The parameters of this command are shown below
Example: useradd -d /home/linux -u 8888 newUser
The -d directive specifies the home directory for the new user. -u Specifies its UID. Note in Linux, the UID of the system administrator is 0. The UID of the system user ranges from 1 to 999. Common user UID starts from 1000. So if we do not specify the UID, the default is 1000. After creating a user, use passwd to set the password for the user.
Groupadd: creates a user group
In the above directive, if a user is created without specifying a user group, a user group with the same name as the user is created by default. If you need to specify a user group, the user group must exist. Then we can use this command.
Example: groupadd admin
Usermod: Modifies user attributes
Anyone who has studied Linux has probably heard that everything in Linux is a file, so users are no exception. The user information is saved in the /etc/passwd file. This can be done directly with the text editor or by using the usermod command.
The parameters of this command are shown below
Example: usermod -u 6666 newUser
Passwd: changes the user password
The passwd command is used to change the user password, expiration time, and authentication information. Ordinary users can only use it to change their own passwords. Only the root administrator can use other functions, and the root administrator does not need to verify the old password when changing its own password or others’ password.
The parameters of this command are shown below
Example: the passwd
If you are the root user, you only need to enter the new password twice. To use other parameters, add the corresponding parameters in the passwd command.
### userdel: Delete a userCopy the code
Example: userdel -r -f newUser
-r forcibly deletes a user, and -f deletes the user’s home directory at the same time.
Su: Switch the user identity
In a learning environment, you can use root, but in a real work environment, you won’t be allowed to do that. We have also learned the new user command, now use the su command to switch to this account.
Example 1: su – newUser
If you switch to a common user as the root user, you do not need to enter a password. In this directive – changes the environment variable information to the information corresponding to the new user. It is recommended to add this minus sign when switching users.
If you switch to root as a common user, you need to enter the password.
Example 2: su – root
When you type this command, the terminal will display a Password and ask you to enter your Password.
Id: Displays user information
Example: id newUser
This is how Linux should Be learned.