Read the instructions
In all command formats, “[]” indicates optional, and “<>” indicates mandatory
Please point out any omissions
Basic commands
-
Switch directory
cd</ Absolute path >For example: CD /home, the absolute path needs to be preceded by a "/" cd< relative path >Example: CD my_dir cd - # return the directory where you were last cd.Switch to the upper directory cd ~ # Switch to home directory cd~< username >Switch to another user's home directory Copy the code
-
File creation, deletion, and file link creation
Touch < file name >Create an empty fileRm [-f] < file name ># Delete file, add "-f" to indicate no queryLn [options] < source file > [destination file]Create a file linkLn -s < source > [target file]# Create soft linksLn < source file > [target file]Create hard links that cannot point to directories or cross devices Copy the code
-
Create directories, copy directories, and delete directories
[option] < directory name >Create a directoryCp [-pdria] < source > < destination >The directory must be copied recursively with "-r"Rm -rf < directory name >"R" indicates recursive deletion Copy the code
-
Copies the matched files to the specified directory
Cp [-pdia] < source file > < destination directory >Copy the code
-
Obtaining administrator Rights
su Switch to user rootSudo < command >Run the command as an administrator Copy the code
-
Creating a New user
Useradd [option] < username ># add userPasswd < username ># set passwordAdduser < user name >You can also use this command # delete userUserdel [-fr] < user name ># "f" indicates forcible deletion, and "r" indicates simultaneous deletion of user and home directories Copy the code
-
Switch the user
Su < username >The root user does not need to authenticate password Copy the code
-
Change directory and file permissions
Chmod [-r] [xyz] < directory/file ># "-r" recursively changes all files in the directory Copy the code
Permissions can also be set using symbols:
The command identity options permissions File or directory chmod U (User) + (increment) R (read) G (group) – (remove) W (write) O (Other Users) = (set) X (execution) A (All identities) Such as:
chmod u+r g-w o=x test # add read permission, group member remove write permission, set other users only execute permission Copy the code
-
Change or add a user group
Groupadd [option] < group name >Create a user groupUsermod [option] < username >Modify user attributesUsermod -g < username ># Change the owning groupUsermod -g < username >Change the extended user group to root, for example, usermod -g rootChown [option][owner][:[group]] < file ># change the file owner and group # such as: chown -hR root:test /u # change owner of all files in /u subdirectory to "root", owner group to "test" Copy the code
Other commands
System work command ###Man < command name >View the command manual
echo[string] | $variablesPrint the value of a string or variable at the terminalDate [option][+ specified format]Display and set the system time
reboot Restart the system
poweroff # Shutdown systemWget [parameter] < download address ># Used to download network files on the terminal
ps [-aux] # Check the process status in the system. You can omit the hyphen (-)
top Monitor process activity and system load in real time, similar to task managerPidof [parameter] < process PID>Query the PID of a specified server process
kill[Parameter] < PID>Stop a process. Use it with caution, which may cause the service to exit unexpectedlyKillall [parameter] < process name >Terminates all processes of a specified named service
System status check command ###Ifconfig [network device] [Parameters]Get the nic configuration and network status
uname [-a] Check the kernel and system version information
uptime Check the current system load information
free [-h] Display the current system memory usage informationWho [parameters]# Check the user terminal information of the current login hostLast [parameter]Check the login records of all systems
history [-c] # Display the executed commands. Add -c to clear the history
Working directory switch command ###
pwd Print the current directoryLs [option] [file]Display information about files in the directory
Text file editing command ###Cat [options] < file ># View plain text content (less content)More [option] < file ># View plain text content (more content)Head [option] < file >View the first N lines of plain text contentTail [option] < file >View the last N lines of plain text content or keep refreshing the contentTr < original character > < target character ># Replace characters in text filesWc [-lwc] < text file ># Count the number of lines, words, and bytes of the specified text
stat< file ># Check the storage information and time of the fileCut [parameter] < file >Extract text content by columnDiff [parameter] < file > < file >Compare the differences between text files
Copy the code
reference
That’s how you learn Linux
Novice tutorial