kill

1$ kill pid # kill -15 pid default kill
The system sends a SIGTERM signal to the corresponding program. When the program receives this signal:
- The program stops immediately.
- The program stops after releasing its resources.
- The program may continue running.
Most programs will release their resources before stopping after receiving the SIGTERM signal. However, some programs can perform other configurable actions upon receiving the signal. If the program is waiting for I/O, it may not respond immediately. This means that SIGTERM is often blocked or ignored.
The kill -15
signal simply notifies the corresponding process to perform a “safe and clean exit.” Before exiting, the program usually performs some “preparatory work,” such as releasing resources, cleaning up temporary files, etc. If the “preparatory work” encounters a block or other issues that prevent it from completing successfully, the application can choose to ignore the termination signal.
1$ kill -9 pid
This is a sure kill, forcing the process to terminate. When executed, the application does not have time to perform “preparatory work,” which often leads to side effects such as data loss or the terminal not returning to a normal state.
ps
The Linux ps
(process status) command is used to display the current process status, similar to the Windows Task Manager.
1$ ps -ef | grep process_keyword # Find the specified process
1# ps -ef | grep php
2root 794 1 0 2020 ? 00:00:52 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
3www-data 951 794 0 2020 ? 00:24:15 php-fpm: pool www
4www-data 953 794 0 2020 ? 00:24:14 php-fpm: pool www
Sometimes the following information is displayed:

In the above query, the results actually do not show the cold process, but they do display the cold process itself. When we query again:

We can see that the process ID keeps changing, whereas normal process IDs do not change.
Solutions:
- Add
[ ]
to any letter in the process name. - Add
grep -v grep
after the process (the-v
parameter means exclude).
cat and tail for viewing logs
1$ tail -f fileName # Display the end of the file on the screen and continuously refresh in real-time.
2$ tail fileName # Display the last 10 lines by default.
3$ tail -n 20 fileName # Display the last 20 lines.
4$ tail -n +20 fileName # Display from the 20th line to the end of the file.
1$ cat fileName # Print the entire log.
mv
1$ mv source_file(file) dest_file(file) # Rename the source file.
2$ mv source_file(file) dest_directory(directory) # Move the source file to the target directory.
3$ mv source_directory(directory) dest_directory(directory) # If the target directory exists, move the source directory under it; otherwise, rename the source directory.
4$ mv source_directory(directory) dest_file(file) # Error.
drwxr-xr-x permissions

The first character indicates the file type: -
for a regular file, d
for a directory, l
for a symbolic link, b
for a block device (hardware storage device).
The remaining characters are grouped into three sets, representing the read, write, and execute permissions for the user, group, and others.
For example, -rwxr-xr-x
or 755
indicates that the user has read, write, and execute permissions, while the group and others have only read and execute permissions.
scp remote copy
Add -r
for directories.
- Copy a file from a remote machine to a local directory. Download the
demo.tar
file from the/tmp/soft/
directory on the machine10.6.159.147
to the/tmp/soft/
directory locally.
1$ scp [email protected]:/tmp/soft/demo.tar /tmp/soft/
- Copy a directory from a remote machine to a local directory. Download the
test
directory from the/tmp/soft/
directory on the machine10.6.159.147
to the/tmp/soft/
directory locally.
1$ scp -r [email protected]:/tmp/soft/test /tmp/soft/
- Upload a local file to a specified directory on a remote machine. Copy the
demo.tar
file from the local/tmp/soft/
directory to the/tmp/soft/scptest
directory on the remote machine10.6.159.147
.
1$ scp /tmp/soft/demo.tar [email protected]:/tmp/soft/scptest
- Upload a local directory to a specified directory on a remote machine. Upload the local directory
/tmp/soft/test
to the/tmp/soft/scptest
directory on the remote machine10.6.159.147
.
1$ scp -r /tmp/soft/test [email protected]:/tmp/soft/scptest
mkdir
1$ mkdir /home/cold # Create a single directory.
2$ mkdir /home/cold /home/cold2 # Create multiple directories in bulk.
3$ mkdir -p /home/cold/coldFile # Create multi-level directories.
find
1$ find /(search scope) -name 'search keyword' -type d # Find a directory.
2$ find /(search scope) -name search keyword -print # Find a file.
1$ find / -name 'tomcat7' -type d # Find the location of the tomcat7 directory.
2$ find / -name 'server.xml' -print # Find the location of the server.xml file.
tar
Source code packages downloaded from the internet are most commonly in .tar.gz
format, with some in .tar.bz2
format.
.tar.gz
format decompression command:tar -zxvf xx.tar.gz
.tar.bz2
format decompression command:tar -jxvf xx.tar.bz2