Just a personal note

1. Use SSH to remotely connect to the server

Secure SHell (SSH) is the most commonly used remote CLI management protocol for Linux, Unix, Mac, and other network devices. SSH encrypts data using secret keys to ensure the security of remote management data.

  1. SSH Username@IP address -p port number (or host domain name) : Log in to a remote host as user root

    For example, SSH [email protected] -p Port numberCopy the code
  2. The SSH root@host IP address + command does not log in to the host but runs only one command on the host

    #Exit with just one command on the server: for example, execute the who command to see which users are logged on to the hostSSH [email protected] -p 3002 whoCopy the code

2. Shut down Linux

Sync synchronize data from the memory to the hard disk shutdown -h now you can set the time or the time to shutdown shutdown -h 20:00 will be shutdown at 8:00 today shutdown -h +10 10 minutes later shutdown -r now Shutdown -r Used to set the restart operation HALT Shutting down the system is equivalent to shutdown -h now and poweroff exit or Logout. The previous operations need to be done before exiting.Copy the code

3. Some common commands

1. CD does not explain


2. Run the ls command

Common parameters:

-l: lists long data strings, including file attributes and permission data. -A: lists all files, including hidden files. -d: lists only the directory itself, not the file data of the directory. -h: lists the file capacity in a readable format (GB, kB, etc.). -r: lists the contents of subdirectories together (recursively), so that all files in the directory will be displayed. These parameters can also be used in combination, for example: ls -l # lists the data files in the current directory as a long data string and ls -lr # lists all files in the current directory as a long data stringCopy the code

3. Grep command

This command is often used to analyze a line of information, if there is the information we need, the line is displayed, this command is usually used with pipe commands, used to filter the output of some commands, etc. Its simple syntax is grep [-acinv] [–color=auto] ‘find string’ filename Its common parameters are as follows:

-C: count the number of times the 'search string' is found -i: ignore case differences, i.e., treat case as the same -v: reverse selection, i.e., display the line without the 'search string' content#Such as:
#Take the line containing MANPATH from /etc/man.config and color the keywords you find
grep --color=auto 'MANPATH' /etc/man.config
#The ls-lContains the letter file (case insensitive) content output in the output of
ls -l | grep -i file
Copy the code

4, find command

Find [PATH] [option] [action] Find [PATH] [option] [action]

#Time-dependent parameters:-mtime n: n is a number, indicating the files that were changed within one day n days ago. -mtime +n: lists the file names that were changed before n days (excluding n days). -mtime -n: lists the file names that have been changed within n days (including n days). -newer file: Newer file names are listed#Such as:Find/root-mtime 0 # Find/root-mtime 0 #
#Parameters related to a user or user group name:-group name: lists the files whose owner is name. -uid n: lists the files whose owner is user N. -gid n: lists the files whose owner is user group N#Such as:Find /home/ljianhui-user ljianhui # In /home/ljianhui to find the file whose owner is Ljianhui
#Parameters related to file permissions and names:-name filename: searches for a file named filename -size [+-] size: searches for a file larger than size (+) or smaller than size (-) -tpye TYPE: searches for a file whose TYPE is TYPE. The value of TYPE can be: General file (F), device file (B, C), directory (D), connection file (L), Socket (s), FIFO pipe file (P); -perm mode: searches for files whose permission is exactly the same as mode. Mode is expressed by a number, such as 0755. -perm -mode: searches for file permissions. Mode is a number. -perm +mode: searches for file permissions#Such as:Find. -perm 0755 # find. -size +12k # find. -size +12k # find. Note that c stands for byteCopy the code

5, cp command

This command is used to copy files, which means copy. It can also copy multiple files to a directory at once. The common parameters are as follows:

-p: copies the features of the file together with the attributes of the file instead of using the default mode. Similar to -a, it is often used for backup. -I: If the target file already exists, the system will ask for the operation before overwriting the file. The target file is copied only if it differs from the source fileCopy the code

For example: cp -a file1 file2 # Copy file1 file2 to file2 cp file1 file2 file3 dir # Copy file1, file2, and file3 to dir


6. Run the mv command

This command is used to move a file or directory or rename it.

-f: force Indicates the force. If the target file already exists, the system overwrites it without asking. -I: If the target file already exists, the system asks whether to overwrite itCopy the code

Note: This command can move one or more files to a folder at a time, but the last destination file must be a directory.

For example, mv file1 file2 file3 dir # Move files file1, file2, and file3 to the directory dir. Mv file1 file2 # Rename file file1 to file2


7. Rm command

This command is used to delete files or directories between remove. Its common parameters are as follows:

-i: in interactive mode, users are asked whether to perform operations before deletion. -r: recursive deletion, most commonly used for directory deletion, is a very dangerous parameter. For example: Rm -i file # Delete all files in directory dir forciblyCopy the code

8. The ps command

This command is used to select and output the running status of a process at a certain point in time. The common parameters are as follows:

-A: all processes that are not related to terminal. -u: processes related to valid users. -x: Generally used together with A to list complete information. PID PID PID PID PID PID PID PID PID PID PID PID PID PID PID PID PID PID PID Ps axjf # to view the status of all processes in the systemCopy the code

9. Kill command

This command is used to send a signal to either a job (%jobnumber) or a PID (number). It is usually used with ps and jobs commands. The basic syntax of this command is as follows:

Kill-signal Common parameters of PID signal are as follows: Note: The first digit is the id of a signal. You can use the id instead of the corresponding signal. 1: SIGHUP: start the terminated process 2: SIGINT: stop a program by pressing CTRL + C 9: SIGKILL: stop a process forcibly 15: SIGTERM: stop a process in the normal way 17: SIGHUP: start the terminated process SIGSTOP is equivalent to CTRL + Z to pause a process. For example:#End the process in the normal way to finally the first background work, availablejobsCommand to view the first worker process in the background
kill -SIGTERM %1 
#Modify the process whose PROCESS ID is PID. You can run the ps command and grep command to obtain the PID
kill -SIGHUP PID
Copy the code

10. Killall command

This command is used to send a signal to a process started by a command. Its general syntax is as follows:

Killall [-iie] [command name] Killall [-iie] [command name] The parameters are as follows: -i: indicates interactive. The user will be asked if the command name needs to be deleted. -e: indicates that the command name must be the same, but the command name cannot exceed 15 characters. The command name ignores case
#Such as:Killall -sighup syslogd # Restart syslogdCopy the code

The file command is used to determine the basic data of the file following the file command. In Linux, file types are not suffixes, so this command is very useful for us. Its usage is very simple, and the basic syntax is as follows:

file filename
#Such as:
file ./test
Copy the code

Tar command

This command is used to package the file. By default, the file is not compressed. If a parameter is specified, the file is compressed and decompressed by calling the corresponding compression program (such as gzip and bzip). Its common parameters are as follows:

-c: creates a package file. -t: displays the file names contained in the package file. -x: indicates the decompression or decompression function, which can be combined with -c (uppercase) to specify the directory to decompress. Compress or decompress using gzip -v: displays the filename being processed during compression or decompression. -f filename: filename indicates the file to be processed. -c dir: specifies the directory dir for compression or decompressionCopy the code

The above explanation can make you pass out, but usually you just need to remember the following three commands:

Compressed: tar -jcv -f filename.tar.bz2 Name of the file or directory to be processed

Query: tar -jtv -f filename.tar.bz2

Decompress: tar -jxv -f filename.tar.bz2 -c Specifies the directory to be decompressed

Note: file names do not have to end with the suffix tar.bz2, mainly to show that the compression program used is bzip2


13. Cat This command is used to view the content of a text file, followed by the file name to be viewed. It can be used together with more and less to view data page by page. Such as:

The cat text | less # view content in a text file
#Note: This command can also be replaced with less text
Copy the code

14. CHGRP command

This command is used to change the user group of a file. It is very simple to use. The basic usage is as follows:

CHGRP [-r] dirname/filename -r: makes continuous changes to all files and subdirectories recursively#Such as:CHGRP users -r./dir # Recursively changes the user group of all files in the dir directory and all files in subdirectories to usersCopy the code

15, chown command

This command is used to change the owner of a file. The method of using this command is the same as that of using the CHGRP command, but the modified file attributes are different.


16. The chmod command

The command is used to change file permissions. The general usage is as follows:

Chmod [-r] xyz file or directory -r: Chmod can also use u (user), G (group), O (other), a (all) and + (join), - (delete), = (set) with RWX to change the permissions of files.
#Such as:-rxwr-xr-x chmod g+w file -rxwr-x chmod g+w fileCopy the code

17, vim command

Operation commands look here


GCC command

GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC GCC

-o: output: specifies the name of the file to generate an executable file. -C: specifies the name of the file to generate an object file (.o) from the source file and prevents the compiler from creating a complete program. -I: adds the path to search for header files at compile time. Lpthread: NPTL implementation thread library -std= : used to specify the C language version to be used

#Such as:
#Compile source file test.c into executable program according to C99 standardtest
gcc -o test test.c -lm -std=c99
#Convert the source file test.c to the corresponding assembler source file test.s
gcc -S test.c
Copy the code

19. The time command

This command is used to measure the execution time of a command (program). It is very simple to use, just like typing a command normally, but just add a time before the command, for example:

Time./ Process time ps aux After the program or command is executed, three times are displayed at the end. User: indicates the CPU time of the user, that is, the total time of executing the command in the user mode. System: system CPU time, the system CPU time spent to complete command execution, that is, the total time of command execution in the core mentality; Real: the elapsed time from the start of the command line to the end of the execution; Note: The sum of the user CPU time and the system CPU time is the CPU time, that is, the total time occupied by the CPU for executing commands. The actual time is greater than the CPU time because Linux is a multitasking operating system, where a command is executed while the system processes other tasks. Another issue that needs to be noted is that even if the same command is executed each time, it takes different time, which is related to the system running.Copy the code

— Constantly updated