In this article, I summarize 21 common Linux commands, which are also used by the interview to test your proficiency in Linux system. You can bookmark or forward the Linux command.

Recommend study courses before the body begins :(can be very useful to help you oh ~)

1, Linux introduction course Linux Cloud computing operation and Maintenance architecture Linux foundation and shell programming _Linux Introduction course Linux Cloud computing operation and Maintenance architecture _shell programming introduction course Shell script basic combat tutorial

2, Java300 sets zero foundation suitable for beginners video tutorial _Java300 sets zero foundation tutorial _Java beginners to learn the video foundation tutorial _Java language entry to master

Javaweb stage exam Java final exam pass through Java programming Java programmer interview questions

Linux_Centos8 Installation and environment configuration _VMWare Common configuration _CentOS8 Installation of MySQL

.

Basic commands for files and directories

1. CD command:

It is used to switch the current directory and takes the path of the directory to switch to, either absolute or relative:

  • 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. 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. Cp copy command

File copy, copy consistent, it can also 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, directory, or name.

  • -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

Used to remove a file or directory; remove implies:

  • -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

.

Second, view the file content

1. The cat command

Used to view the contents of a text file, followed by the file name to view, usually with pipes used 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 (that is, according to 3000 ~ 3999 rows) \

.

File search

1. 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:

Find /var/mail/-size +50M -exec rm {} \;Copy the code

.

Four, the file permission command

Use “+” to set permission, use “-” to cancel

1. 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

2. The chown command

Change the owner of the file:

  • 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

3. The CHGRP command

Change the owning user group of a file:

  • CHGRP group1 file1 Specifies the group that changes the file

.

5. Text processing

1. The grep command

Parses a line of information and displays 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 delete all blank lines from example. TXT

2. 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

3. 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)

4. The comm 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

1. The tar command

By default, the file is not compressed. If 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

1. The JPS command

Display the status of the Java process in the current system and its ID:

  • 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.

2. The ps command

Used to select and output the operation of a process at a 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
Ps axjf # to view the status of all processes in the systemCopy the code

3. Kill command

Used to send a signal to a job (%jobnumber) or to a PID (number). It is usually used with ps and jobs commands:

4. The killall command

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

5. 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:

Netstat tunlp | grep port numberCopy the code

The above is all the content of this chapter, I will update the follow-up oh, like the partner support oh ~

Thanks for watching ~