Linux operation commands

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 ;

insert image description here
(2) -k: The size of the file is expressed in k bytes;

insert image description here
(3) -l: List the details of the file

insert image description here
(4) -r: Sort the directory in reverse
insert image description here
(5) -t: Sort by time

insert image description here

(6) -R: List files in all subdirectories
(7) ls /: Display all files in the root directory

insert image description here

Noticels /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

insert image description here

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) tabKey completion;

When entering, if you forget to include those files, enter twice and you tabwill 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 ( 不是文件夹);

insert image description here

(5) mkdir : create a directory

mkdir 目录名称: Create a directory
insert image description here
Here is to create a tdirectory named, if it already exists, an terror will be reported;

If the path has multiple levels, use -p;

(6) rm: delete file/directory

rmPath to file or directory: Delete a file or directory

By default it will prompt

insert image description here
Create a new one text.txt, use -fDelete, there will be no prompt message
insert image description here
-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.txtfile to the tdirectory:
insert image description here

-R: copy folder

(8) mv: move the file to the target directory

mv 源路径 目标路径: move a file to a directory

eg : test.txtmove to tthe folder
insert image description here
move the tdirectory test.txtto the current directory and name ittest2.txt
insert image description here

2, the operation of the file content

(1) cat: View the contents of the target file

cat 文件路径: show all the contents of the file

insert image description here

(2) vi: text editor

Two modes:

  • read-only mode:Can not be modified

Read-only mode to enter edit mode :
(1) Press i: the current cursor position, insert new content;
(2) Press o: the next line of the current cursor, insert a new line;
exit the program: input :wqsave and exit ( wmeans save, qmeans exit) Enter :q!Force exit without saving;
search :
/搜索的内容: The cursor moves to the first matching position, and when pressing n, switches to the next matching position, and shift+nswitches 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: press u;

  • edit mode: The keyboard input will be inserted into the text

Edit mode to enter read-only mode: pressesc

(3) less: view file content

grammar:less [参数] 文件

parameter:

  • -NDisplay the line number of each line

insert image description here
show:
insert image description here

Click qto 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 the test.txtprevious 10line
as follows:
insert image description here

(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 :
insert image description here

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行的内容
insert image description here

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行的内容

insert image description here

(6) grep: find whether the file contains the specified string

grep “搜索的内容” 文件/目录路径: Search in a file or directory and match the searched content

insert image description here
Often with the pipe symbol, the output of a certain instruction is searched for:

Such astest.txt : 10search for a string in the previous element, freturn if there is, not return if not;
insert image description here

3. man view instruction command

man 命令名称: Viewing the description of a command ( 包括命令参数)
will enter the document reading mode;

insert image description here
in:

j:向下一行翻 k:向上一行翻 q:退出

/ 搜索的内容: Search for the matching string, after the search is found, press nto find the next matching position, and press to shift+nmatch 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
insert image description here

4. About the network

(1) netstat: View the network status on the system

netstat -anp: Display network information for all processes

insert image description here

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"

insert image description here
Generally speaking, first find the process netstatby the port number pid, and then use psby to pidfind the process information;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324311547&siteId=291194637