Explanation of common LINUX commands

Keywords: Linux

1.shell: command parser. When entering a command in the terminal, it will be parsed by the shell and execute an executable file with the same name. You can view which shells the current system supports through cat /etc/shells. Use echo $SHELL. Shell is the environment variable
$is the value of the environment variable to view the command parser being used by the current operating system.
2. Main keyboard shortcut:

ctrl+a Move the cursor to the beginning
ctrl+e Move cursor to end
ctrl+d Delete the element behind the cursor
ctrl+u Deletes all elements in front of the cursor
clear Clear screen
cd .. Jump to the previous directory
cd - Jump to the last accessed directory
ls View files in the current directory
pwd View the path of the current directory
cd / Jump to root directory
cd ~ Jump to the current user directory to represent home
cd Quickly switch back to user home directory

3. Directory operation

mkdir name Used to create a directory
touch name Create a new file
ls -a Show hidden files
ls -d display contents
ls -l mulu View details of files in a directory
ls -dl mulu View information about the directory itself
ls -R Recursively view directories and subdirectories
ls -Rl Recursively enter and expand details
which View the directory location of the command
rmdir name Delete an empty directory
rm -r name Recursively delete files in a directory

Directory under root directory:

bin: store executable files
Boot: store the boot program
dev: store devices. Each device corresponds to a file. The changes of the device are converted into the input of the file
etc: some configuration file information of the current system user
home: user name
lib: library file
Root: the home directory of the root directory
usr: user related files, programs, files and libraries installed by users themselves
4. Path operation
Absolute path: the path from the root directory
Relative path: the path to operate from the current location
cd. Operate relative to the current directory. In other words, add. To omit all operations in front of the absolute path and directly continue the current backward operation
5.linux file type
View by: ls -l first character
Normal file (hard link):-
Catalog file: d
Character device file: c
Block device file: b
Soft connection: l
Pipe files: p
Socket: s
5. File operation

Copy file
cp wenjian mulu Copy files to directory
cp wenjian1 wenjian2 Create a new file 2 and include the contents of file 1
 replica catalog 
cp -r/-a mulu lujing Copy all files in the directory to the specified path
 Note:-a and-r The difference between,-a yes all Permission, owner, group, hard link count and time will be copied 
cat wenjian view file contents
more wenjian View large files
head -5 wenjian View the first 5 lines of the file
tail -5 wenjian View the last 5 lines of the file
cat Separate readable terminal
tac wenjian Reverse output file
tree Display the current directory structure in the form of a tree diagram

6. File read / write permission
chmod
Text setting method

chmod who +|-|= mode file
who:
u Represents the user, the owner of a file or directory
g Indicates the same group of users, that is, the file attributes have the same group ID All users of
o Represents another user
a Represents all users, which is the system default
chmod u+x a.c
chmod o-r a.c

Digital setting method

Read permission r---4
 Write permission w---2
 Execution Authority x--1
chmod ugo(Set number) file name
chmod 421 a.c  take a.c File user owner permission is set to read-write, users in the same group are set to write, and other users are set to execute

7. User modification
Add users and user groups

whoami View current users
sudo passwd yonhuming Set user password
sudo adduser zhangsan Add new user
sudo addgroup zuming Add user group

Go to passwd under etc to view the information of the newly created user

zhangsan:1001:1001
 It represents the number of the current user and the number of the user group respectively. The operating system accesses the user through the number

Change file owner and user group

sudo chown zhangsan a.c take a.c User owner changed to zhangsan
sudo chgrp zuming a.c modify a.c User group to which the file belongs
sudo chown nobody:nogroup a.c Set the user and user group at the same time

Delete users and user groups

sudo deuser zhangsan
sudo degroup zuming

8. Search and retrieval
Find: find file
-Type searches by file type
-Name searches by file name
-maxdepth specifies the search depth
-Size search by file size unit: k M G
-exec: execute a specified command on the result set of find search

find ./ -type 'd' Find the directory file in the current directory
find ./ -type f View files in the current directory
find ./ -name '*.jpg' Find the in the current directory jpg file
find -maxdepth 2 -mame '*.jpg' Specifies the directory level for the search
find ./ -size +20k -size -50k Find the current directory with a size of 20 k To 50 k Files between
find ./ -name "*tmp" -exec ls -l {} \;Find the suffix in the current directory tmp And execute the display configuration information, with escape characters at the end

grep command: find file content retrieval

grep -r 'copy' ./ Search the contents in the current directory that contain copy For the content of words, when there are many words to search, it is best to enclose them in single quotation marks or double quotation marks
ps aux Call out all background processes of the current system
ps aux | grep zhangsan User Zhang San related processes

Note: when searching for processes with grep, there is only one, which is itself, that is, there is no relevant process searched
The single find command cannot be given to the pipeline operation, and xargs needs to be added
xargs command:
When the number of result sets is too large, it can be mapped in pieces, which is faster than the pipeline. It takes spaces as the split basis. However, when there are spaces in the file name, the processing of the result set will make errors. print0 needs to be added and NULL as the split basis

find ./ -maxdepth 1 -type f | xargs ls -l Use the pipeline to display the information of ordinary files under this path
 Equivalent to find ./ -maxdepth 1 -type f | -exec ls -l {} \;
find ./ -maxdepth 1 -type f print0 | xargs print0 ls -l Avoid having in the result set, for example, a file named abc xyz Display error of

9. Other common commands
Alias: alias

alias ck 'ps aux | grep' to ps aux | grep Start one ck Alias for
 implement ck abc == ps aux | grep abc The content of the process running in the background is abc Process of

Umask: Specifies the mask when the user creates a file. By default, the operating system removes the execution permission of all newly created files. The default permission is 777, which is readable, writable and executable. After removing the execution, it is 666. After subtracting the mask, it is the created file permission. For example, when unask is 002, the created file permission is normally 775, including the execution permission. After removing it, it is 664. When umask permission is 511, The permission of the created file is normally 266, and there is no execution permission, so you do not need to execute the permission, that is, 266 (– w-rw-rw-)

umask 511   Change the create file permission mask to 511

Terminal operation:
Create a new terminal: ctrl+alt+t
Create paging terminal: ctrl+shift+t operate alt+1... n in paging terminal
Close terminal: ctrl+d

Posted by tisource on Tue, 14 Sep 2021 14:56:24 -0700