Linux operation commands
-
- 1, the operation of the file directory
-
- (1) ls: Display directories and files
- (2) cd: switch to a directory
- (3) pwd: Display the directory where the current user is located
- (4) touch: change document/directory date
- (5) mkdir : create a directory
- (6) rm: delete file/directory
- (7) cp: copy files/directories
- (8) mv: move the file to the target directory
- 2, the operation of the file content
- 3. man view instruction command
- 4. About the network
1, the operation of the file directory
(1) ls: Display directories and files
Syntax: ls [选项] [目录或文件]
: Display the files in the next level of the path;
Common options:
(1) -a
: List all files in the directory, including .
hidden files starting with ;
(2) -k
: The size of the file is expressed in k bytes;
(3) -l
: List the details of the file
(4) -r
: Sort the directory in reverse
(5) -t
: Sort by time
(6) -R
: List files in all subdirectories
(7) ls /
: Display all files in the root directory
Notice:ls /bin =ls ./bin = ls bin
The first one is the absolute path writing method, the last two are the relative path writing method
Linux
, .
the file at the beginning represents a hidden file;
(2) cd: switch to a directory
cd 路径
: switch to a directory
cd ~
: switch to user directory
cd /
: switch to the root directory
cd -
: return to the most recently accessed directory
cd ..
: return to the parent directory
(3) pwd: Display the directory where the current user is located
pwd
: Displays the directory the user is currently in
Notice:
(1) Several special directories:
/
root directory.
called the current directory..
the parent directory called the current directory
(2) Absolute path and relative path:
/
Absolute paths starting with- start with
.
or..
start with as a relative path
(3) tab
Key completion;
When entering, if you forget to include those files, enter twice and you tab
will be prompted~
(4) touch: change document/directory date
touch 文件路径
: If the file exists, modify the last update time of the file to the current time, if it does not exist, create a new file ( 不是文件夹
);
(5) mkdir : create a directory
mkdir 目录名称
: Create a directory
Here is to create a t
directory named, if it already exists, an t
error will be reported;
If the path has multiple levels, use -p
;
(6) rm: delete file/directory
rm
Path to file or directory: Delete a file or directory
By default it will prompt
Create a new one text.txt
, use -f
Delete, there will be no prompt message
-r
: Recursively delete all contents in the directory
Notice: rm -rf /
must not do this arbitrarily
(7) cp: copy files/directories
grammar:cp 源文件或目录 目标文件或目录
eg : Copy the test.txt
file to the t
directory:
-R
: copy folder
(8) mv: move the file to the target directory
mv 源路径 目标路径
: move a file to a directory
eg : test.txt
move to t
the folder
move the t
directory test.txt
to the current directory and name ittest2.txt
2, the operation of the file content
(1) cat: View the contents of the target file
cat 文件路径
: show all the contents of the file
(2) vi: text editor
Two modes:
- read-only mode:Can not be modified
Read-only mode to enter edit mode :
(1) Pressi
: the current cursor position, insert new content;
(2) Presso
: the next line of the current cursor, insert a new line;
exit the program: input:wq
save and exit (w
means save,q
means exit) Enter:q!
Force exit without saving;
search :
/搜索的内容
: The cursor moves to the first matching position, and when pressingn
, switches to the next matching position, andshift+n
switches to the previous one;
g连点两下
: The cursor switches to the beginning of the document;
shift+g
: The cursor switches to the end of the document;
restore Last modified content: pressu
;
- edit mode: The keyboard input will be inserted into the text
Edit mode to enter read-only mode: press
esc
(3) less: view file content
grammar:less [参数] 文件
parameter:
-N
Display the line number of each line
show:
Click
q
to exit;j
: scroll up the screen;k
: scroll down the screen;
(4) head: Display the content of the file
head -n 行数 文件路径
: Display the content of the file, and display the total number of lines from the front to the back
eg
: Display the content of thetest.txt
previous10
line
as follows:
(5) tail: display file content
tail -n 行数 文件路径
: Display the content of the file, from the last line to the previous [line number]
as shown below :
Pipe |
: The way of inter-process communication: the output of the left process is used as the input of the right process;
eg:输出test.txt第10行的内容
common usage:
To output a file, the contents of lines from x to y:
head -n[y] 文件路径 | tail -n[y-x+1]
tail -n[总行数-x+1] 文件路径 | head -n[y-x+1]
Such as :显示 test.txt 文件中,从 第 6 行到第10行的内容
(6) grep: find whether the file contains the specified string
grep “搜索的内容” 文件/目录路径
: Search in a file or directory and match the searched content
Often with the pipe symbol, the output of a certain instruction is searched for:
Such astest.txt
: 10
search for a string in the previous element, f
return if there is, not return if not;
3. man view instruction command
man 命令名称
: Viewing the description of a command ( 包括命令参数
)
will enter the document reading mode;
in:
j:向下一行翻 k:向上一行翻 q:退出
/ 搜索的内容
: Search for the matching string, after the search is found, pressn
to find the next matching position, and press toshift+n
match the previous one; (This is also done in document reading mode)
g
: switch to the first line of the document,shift+g
: switch to the end of the document;
eg: searchall
4. About the network
(1) netstat: View the network status on the system
netstat -anp
: Display network information for all processes
If not, you need to install a package first, the command is:
yum install -y net-tools
Among them :
yum
: means to download and install a program online through the network;install
: indicates installation;net-tools
: package name;
(2) ps: View the processes running on the current system
ps
: View process information
(1)
ps aux | grep "进程名称/pid"
(2)ps -ef | grep "进程名称/pid"
Generally speaking, first find the process netstat
by the port number pid
, and then use ps
by to pid
find the process information;