Table of contents
Know the Linux directory structure
Absolute path: starting with the root directory, called an absolute path
Relative path: It does not start with the root directory, it is called a relative path
1. Query the corresponding process id according to the process name
2. View the corresponding process according to the port number
3. View the corresponding bound port number according to the process id
Several important hotkeys [Tab], [ctrl]-c, [ctrl]-d
Know the Linux directory structure
special directory:
/ is called the root directory. is called the current directory.. is called the parent directory of the current directory
Absolute path: starting with the root directory, called an absolute path
Like : /usr/share/tomcat/logs/
Relative path: It does not start with the root directory, it is called a relative path
Shapes like : ./logs starting with . or .. are called relative paths .
ls
View the content of the specified directory, similar to double-clicking the D drive in Windows system to view the content of the D drive
- -a lists all files in the directory, including hidden files starting with .
- -d Display the directory as a file instead of the files under it. Such as: ls -d specifies the directory
- -k indicates the size of the file in k bytes. ls –alk specifies the file
- -l lists detailed information about the file.
- -r Sort directories in reverse.
- -t Sort by time.
- -R lists the files in all subdirectories. ( recursive )
example
ls -l
ls -l can list all files in the current directory, ls -l can be simplified to ll (here l is a lowercase L)
pwd
View your current directory
Example: In case we get lost and don’t know which path we are in, we can use pwd to check our current absolute path
cd
Switch to the specified directory, which can be understood as double-clicking a directory to enter
- cd .. Back to the previous directory
-
cd ~ : enter the user's home directory
-
cd - : return to the most recently visited directory
mkdir
Create new directory folder (i.e. create new folder)
- mkdir -p xxx/yyy creates a multi-level directory
touch
Create a new file, for example, create a 123.txt file
Example: touch 123.txt
cat
View the contents of a file in a folder
echo
write file content
Example: echo "hello" > 1.txt
rm
Delete a file or directory (folder)
- -f Even if the file attribute is read-only (that is, write-protected), delete it directly
- -i Ask for confirmation one by one before deleting
- -r delete directory and all files under it recursively
Example: rm -i test.txt
Important notes:Do not run rm -rf /, especially on the company's production server (/ is the root directory, r is recursive, f is directly deleted as long as it is a file)
cp
Copy a file or directory (folder)
- -f Forcefully copy a file or directory, regardless of whether the destination file or directory already exists
- -i ask user before overwriting files
- -r Recursive processing, processing files and subdirectories under the specified directory together. If the form of the source file or directory does not belong to a directory or a symbolic link, it will be treated as an ordinary file
Note: If cp is copying a directory (folder), the -r option is required to recursively copy all files in the directory, otherwise an error will be reported
Example: cp test1.txt test2.txt
mv
rename or move
Example: mv test1.txt test2.txt to rename
ps and netstat
Use the netstat command: The netstat command can display network connections, routing tables, and network interface information. You can use the netstat command to check which process a certain port is occupied by.
The specific command is: netstat -nap | grep port number, where the port number is the port number to be queried.
1. Query the corresponding process id according to the process name
ps -ef | grep 进程名 #根据进程名查进程pid
ps -aux | grep 进程名或进程id #可以查到该进程占了多少CPU和内存占用比
2. View the corresponding process according to the port number
netstat -nap | grep 端口号 //其中端口号为需要查询的端口号。
3. View the corresponding binding port number according to the process id
netstat -nap|grep pid //pid为进程
vim editor
1. Enter the file
Syntax: :vim filename
Example: vim 1.txt
Enter the vim interface
2. Enter edit mode
3. Save and exit
When we finish typing in the vim edit box, we want to save and exit. At this point you need to switch from insert mode to normal mode. Files cannot be saved in insert mode , you need to return to normal mode first .
Steps: 1. Press the Esc key to return to normal mode .
Several important hotkeys [Tab], [ctrl]-c, [ctrl]-d
If there is only one matching item, press the tab key to complete it automatically. If there are multiple matching items, press the tab key twice to display all the matching items