I. Files and directories

1. The CD command

(It is used to switch the current directory, and its argument is the path to the directory to switch to, can be an absolute path or a relative path)

  • CD /home Go to the ‘/ home’ directory
  • cd .. Returns the upper directory
  • cd .. /.. Returns the previous two levels of directories
  • CD goes to the personal home directory
  • CD ~user1 Go to the personal home directory
  • CD – Returns the last directory

2. The PWD command

  • PWD Displays the working path

3. The ls command

Command to view files and directories

  • Ls Displays files in a directory
  • Ls -l Displays detailed information about files and directories
  • Ls -a Lists all files, including hidden files
  • Ls -r is listed (recursively) with the contents of subdirectories, equal to all files in that directory are displayed
  • Ls [0-9] Displays the file name and directory name containing digits

4. The cp command

(Copy means to copy files, it can also be used to copy multiple files to a directory at a time)

  • -a: copies the features of the file together
  • -p: copies the file with its attributes 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 about the operation before overwriting the file
  • -r: indicates recursive continuous replication, used for directory replication
  • -u: copies the target file only when the target file is different from the source file

5. The mv command

(used to move a file or directory or rename it)

-f: force Indicates the force. If the target file already exists, the system overwrites the file directly

-i: If the target file already exists, the system asks whether to overwrite it

-u: The file will be updated only if the target file already exists and is newer than the target file

\ 6. The rm command

Remove (used to remove a file or directory)

  • -f: indicates force. If a file does not exist, no warning message will be displayed
  • -i: in interactive mode, the system asks the user whether to perform the deletion
  • -r: Recursive deletion, most commonly used for directory deletion, is a very dangerous parameter

Special recommendation: 30,000 words summary Java self-study, in-depth notes, learning materials

Second, view the file content

7. The cat command

(Used to view the contents of a text file, followed by the file name to view, usually used with pipes with more and less)

  • Cat file1 Forwards the file from the first byte
  • Tac file1 looks at the contents of a file in reverse, starting with the last line
  • Cat -n file1 indicates the number of lines in a file
  • More file1 Displays the contents of a long file
  • Head -n 2 file1 Displays the first two lines of a file
  • Tail -n 2 file1 Displays the last two lines of a file
  • Tail -n +1000 file1 Starts at 1000 lines and is displayed after 1000 lines
  • The cat filename | 3000 | head – n tail – n + 1000 show lines 1000 to 3000
  • Cat filename | tail – n + 3000 | head – n 1000 from line 3000, according to 1000 line (that is, according to 3000 ~ 3999)

File search

8. The find command ()

  • Find / -name file1 Searches for files and directories in the root file system starting with ‘/’
  • Find / -user user1 Searches for files and directories belonging to user ‘user1’
  • Find /usr/bin-type f-atime +100 Searches for execution files that have not been used in the past 100 days
  • Find /usr/bin-type f-mtime-10 Searches for files that have been created or modified within 10 days
  • Whereis Halt displays the location of a binary, source, or MAN
  • Which HALT displays the full path to a binary or executable file

Delete files larger than 50M:

Four, file permissions – use “+” to set permissions, use “-” to cancel

9. The chmod command

  • Ls -lh Displays permissions
  • Chmod ugo+ RWX directory1 Sets owner (u), group (g), and other (o) permissions for the directory to read (r, 4), write (w, 2), and execute (x, 1)
  • Chmod go-rwx directory1 Deletes the read/write permissions of the group (g) and others (O) on the directory

10. Chown command

(Change file owner)

  • Chown user1 file1 changes the owner attribute of a file
  • Chown -r user1 directory1 Changes the owner properties of a directory and the properties of all files in the directory
  • Chown user1:group1 file1 Changes the owner and group properties of a file

11. The CHGRP command

(Change the user group of a file)

  • CHGRP group1 file1 Specifies the group that changes the file

5. Text processing

12. The grep command

(Analyze a line of information and display it if it has the information we need. This command is usually used with pipe commands to filter the output of some commands, etc.)

  • Grep Aug /var/log/messages Find the keyword “Aug” in the file ‘/var/log/messages’
  • Grep ^Aug /var/log/messages Look for words starting with “Aug” in the file ‘/var/log/messages’
  • Grep [0-9] /var/log/messages Select all lines containing numbers in the ‘/var/log/messages’ file
  • Grep Aug -r /var/log/* Search for the string “Aug” in the directory ‘/var/log’ and subsequent directories
  • Sed ‘s/stringa1/stringa2/g’ example. TXT replace “string1” in example. TXT with “string2”
  • Sed ‘/^$/d’ example.txt deletes all blank lines from example.txt

13. The paste command

  • Paste File1 file2 Combines the contents of two files or columns
  • Paste -d ‘+’ file1 file2 Combines the contents of two files or columns with “+” between them

14. The sort command

  • Sort file1 file2 Sorts the contents of two files
  • Sort file1 file2 | uniq took out two file and set the line only keep a (repeat)
  • Sort file1 file2 | uniq -u delete intersection, leaving the other line
  • Sort file1 file2 | uniq – d out the intersection of two files (leaving only exists in two files in the file at the same time)

15. com m command

  • Comm-1 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file1’
  • Comm-2 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file2’
  • Comm-3 file1 file2 Compares the contents of two files and deletes only the common parts of the two files

Package and compress files

16. The tar command

(The file is packaged. By default, it is not compressed. If the parameter is specified, it will call the corresponding compression program (such as gzip and bzip, etc.) for compression and decompression.)

  • -c: Creates a package file
  • -t: displays the file names in the packaged file
  • -x: Indicates the decompression or decompression function. It can be combined with -c (uppercase) to specify the decompression directory. -C,-t, and -x cannot appear in the same command at the same time
  • -j: Compression/decompression with bzip2 support
  • -z: uses gzip to compress or decompress
  • -v: displays the file name being processed during compression or decompression
  • -f filename: filename indicates the file to be processed
  • -c dir: specifies the directory dir for compression or decompression
  • 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
  • Bunzip2 file1.bz2 unzip a file called ‘file1.bz2’
  • Bzip2 file1 compresses a file called ‘file1’
  • Gunzip file1.gz Unzip a file called ‘file1.gz’
  • Gzip file1 compresses a file called ‘file1’
  • Gzip-9 File1 Maximum compression
  • Rar a file1.rar test_file creates a package called ‘file1.rar’
  • Rar a file1. Rar file1 file2 dir1 Compresses ‘file1’, ‘file2’ and directory ‘dir1’ simultaneously.
  • Rar x file1.rar Decompresses the RAR package
  • Zip file1. Zip file1 Creates a zip package
  • Unzip file1.zip Decompresses a zip package
  • Zip -r file1.zip file1 file2 dir1 Compresses several files and directories into a zip package

Vii. System and shutdown (shutdown, restart and logout of the system)

  • Shutdown -h now Shutdown system (1)
  • Init 0 Shut down the system (2)
  • Telinit 0 Shutdown system (3)
  • Shutdown -h hours:minutes & shutdown the system at the scheduled time
  • Shutdown -c Cancels shutting down the system at the scheduled time
  • Shutdown -r now Restart (1)
  • Reboot to restart (2)
  • Logout logout
  • Time Measures the execution time of a command (program)

Process-related commands

17. The JPS command

(Display the Java process of the current system and its ID number)

  • JPS (Java Virtual Machine Process Status Tool) is a command provided by JDK 1.5 to display the PID of all Java processes. It is simple and practical. It is very suitable for viewing the simple situation of the current Java Process on Linux/Unix platform.

18. The ps command

(Used to select and output the running status of a process at a certain point in time.)

  • -a: All processes are displayed
  • -a: indicates all processes that are not related to terminal
  • -u: processes related to valid users
  • -x: used together with parameter A to list complete information
  • -l: Lists PID information in a long and detailed manner

19. Kill command

(Used to send a signal to either a job (%jobnumber) or a PID(number), usually with ps and jobs commands)

20. The killall command

(Sends a signal to a process started by a command)

21. The top command

It is a common performance analysis tool in Linux. It displays the resource usage of each process in the system in real time. It is similar to the Task manager in Windows.

How to kill processes:

  • Graphical interface
  • Kill -9 PID (-9 indicates forcible shutdown)
  • Killall-9 the name of the program
  • Name of the pkill program

Check the process port number: