Basic Linux commands that Xiaobai can learn (middle)

1. Directory related commands

In practical applications, there are two main operations related to directories: creating directories and deleting directories.

1.1 Create directory mkdir (make directory)

Role: Create a directory
Syntax: mkdir path (need to include the folder name)
Usage 1: Create a directory
Insert picture description here

特别注意:mkdir 命令默认不能隔级创建目录,必须要求要创建的目录所在的目录一定要存在,如果想
创建多层不存在的路径,可以使用 mkdir -p进行实现。

Usage 2: Recursively create a directory.
Role: Used to create multiple layers of non-existent paths, mainly to supplement usage one [-p: means parents, the meaning of parents]
Syntax: mkdir -p path (need to include the directory name)
in /usr/ The amo directory does not exist in the local directory. Recursively create /usr/local/amo/projects.
Insert picture description here
Usage 3: Create multiple directories at the same time.
Syntax: mkdir [-p] Path 1 Path 2 Path 3
Insert picture description here

1.2 Delete the directory rmdir (remove directory)

Role: Delete directory
Syntax: rmdir path (need to include the directory name)
Use one: delete empty directories and delete multiple empty directory
Insert picture description here
usage II: recursive delete empty directories
Syntax: rmdir -p path
after first deleting subdirectories, delete success: the role of , Delete the parent directory until the end
Insert picture description here

2. File operations

In actual applications, there are mainly two file-related operations: creating files and deleting files.

2.1 Create file touch

Function: Create file
Syntax: touch file path [File path 2 File path 3...]
Usage 1: Create readme.txt file
Insert picture description here
Usage 2: Create multiple files at the same time
Insert picture description here

2.2 Delete file rm (remove)

Function: delete a file or folder.
Syntax: rm [-rf] file or folder path.
Options: -r: delete recursively -f: delete forcibly, without prompting any information. Be careful before operation! ! !
Usage 1: Delete the readme.txt file
Insert picture description here
Usage 2: Recursively delete directories
Insert picture description here
Usage 3: Force delete files or directories
Insert picture description here

3. Copy and Cut

3.1 Copy operation cp (copy)

Function: Copy the file/folder to the specified location.
Syntax: cp [-r] The path of the copied file. The
option of the path to which the file is copied : -r: recursion, recursive, which means that all subordinate files/folders in the folder Copy all. If you are using the cp command to copy a folder, -r is not an option, but a required item.
Note: The name of the document is unchanged during the copying process.
Usage 1: Copy /root/readme.txt to the /tmp directory.
Insert picture description here
Usage 2: : Copy the /root/shop directory to the /tmp directory
Insert picture description here

3.2 Cut operation mv (move, move, cut)

Function: Move the document to a new location.
Syntax: mv The path of the document that needs to be moved The location where the path needs to be saved The difference between mv and cp is as follows:

  1. The mv command is different from the cp command, no matter it is for files or folders, there is no need to add options like -r.
  2. In the process of moving, the name of the document is unchanged, but the path is changed

Cut and move files:
Insert picture description here
Cut and move folders:
Insert picture description here

3.3 Rename operation

The renaming command in Linux is also mv, the syntax is the same as the move syntax. The difference is that when renamed, the path is generally unchanged, but the name is changed. [While moving is the same name, the path changes]
Insert picture description here

4. Compression and decompression

4.1 gzip | bzip2 | xz compression and decompression commands

gzip | bzip2| xz: compress a single file

☆ gzip command
Syntax 1: gzip files that need to be compressed
Insert picture description here
Syntax 2: gzip file1 file2 compresses multiple files at the same time. The compression
Insert picture description here
speed is fast, the compression rate is low, and the cpu overhead is relatively low.
Decompression: gunzip or gzip -d
Insert picture description here
☆ bzip2 command
compression: bzip2 needs to be compressed File
Insert picture description here
decompression: bzip2 -d files that need to be decompressed have
Insert picture description hereslow compression speed, high compression rate, and high cpu overhead

☆ xz command
High compression rate, fast decompression speed, longer compression time, relatively large cpu consumption
Compression: xz files that need to be compressed
Insert picture description here
Decompression: unxz or xz -d
Insert picture description here

4.2 tar packaging command

When the gzip, bzip2, or xz command takes multiple files as parameters, the operation performed is to compress each file independently, rather than putting them together for compression. This will not produce results similar to the Windows environment files under the folder packaged compressed, packaged in order to achieve the effect of compression, you can use the command tarto package file operations (archive), and then compressed.

tar Commands can pack files into archives and store them on disks/tapes. The packing operation usually accompanies the compression operation. You can also use the tar command to decompress the packed and compressed files.

4.2.1 Packaging

Syntax: tar option package file name file or directory to be packaged
Options:

  1. -c, the meaning of create
  2. -v, the meaning of visualization, that is, you can view the creation process, you can omit
  3. -f, required parameter, cannot be omitted
  4. u, the abbreviation of update, update the file in the original package file (understand)
  5. r, append meaning, append a file to the end of the compressed archive file (understand)
  6. -t, view the contents of the packaged file (understand)
    Insert picture description here

Add the readme.txt file to the test.tar package. -r means adding files. as follows:
Insert picture description here

4.2.2 Package and compress (emphasis)

When tar is packaged, it supports compression. The gzip, bzip2, and xz compression tools above can all be used in tar packaged files.
Syntax: tar option package file name to be compressed file or directory
Options:

  1. -z, compressed to .gz format
  2. -j, compressed to .bz2 format
  3. -J, compressed to .xz format
  4. c, the meaning of create
  5. v, the meaning of visualization, that is, you can view the creation process, you can omit
  6. f. Use the file name. Remember, this parameter is the last parameter, and only the file name can be followed. Required parameters, cannot be omitted

Compress hello.txt, readme.txt and world.txt into test.tar.gz files
Insert picture description here
Compress hello.txt and world.txt into test.tar.xz files
Insert picture description here

4.2.3 Unzip

When decompressing, replace c in the compression command with x to
decompress the test.tar.gz file.
Insert picture description here
Decompress the test.tar.xz file.
Insert picture description here
Use the option -tf to view the contents of the compressed file, and all three formats of compressed files are applicable.
Insert picture description here

4.2.4 zip compression and decompression (understand)

(1) zip compression
command: zip
function: compatible with unix and Windows, can compress multiple files or directories.
Syntax: zip [-r] compressed files need to be compressed files (multiple files)
option: -r recursive compression
Note : Zip The default compressed format is .zip, of course, you can also add the suffix .zip, generally you can add it.
Usage 1: File compression
Insert picture description here
Usage 2: Folder compression
Insert picture description here
(2) unzip decompression
command: unzip
function: decompress file
syntax: unzip the compressed file to be decompressed[-d] Decompression directory
Options: -d, the abbreviation of directory, which means to decompress the file to the specified directory.
Usage 1: decompress to the current directory.
Insert picture description here
Usage 2: decompress to the specified directory
Insert picture description here

5. View file content

5.1 View in positive order

Command: cat
Function: View the contents of the file in positive order
Syntax: cat file name
Insert picture description here

5.2 File content merge

In fact, the cat method also has a very useful function, which can merge file contents.
Syntax: cat file path to be merged 1 file path to be merged 2...file path n> file path after merge
Insert picture description here

5.3 View in reverse order

Command: tac
Function: View file content in reverse order
Syntax: tac file name
Insert picture description here

6. Output redirection

Scenario: The output of general commands will be displayed in the terminal. Sometimes it is necessary to save the execution results of some commands to a file for subsequent follow-up 分析/统计, then it is needed at this time 输出重定向技术.

  1. >: Standard output redirection ⇒ overwrite output, the original file content will be overwritten
  2. >>: Append redirection ⇒ Append output, will not overwrite the original file content, will continue to add at the end of the original content

Syntax: the output command that needs to be executed, output redirection symbol> or >> the file path to the output
Note: The file in the file path can be a non-existent file (the file path must meet the requirements of touch creation)
Usage 1: output heavy Directional
Insert picture description here
Usage 2: echo command, function: string output
Insert picture description here
Usage 3: use echo command to write custom content to the file
Insert picture description here

6.1 Extension: standard input and output

I/O input and output of bash:

  1. Standard input (stdin): the content entered on the keyboard file descriptor ⇒ 0
  2. Standard output (stdout): the correct result file descriptor output on the screen ⇒ 1
  3. Standard error (stderr): The result of the error output on the screen. File descriptor ⇒ 2
    Insert picture description here
  4. Standard error redirect
    Insert picture description here
  5. &>: Standard output and standard error redirection
    Insert picture description here

7. Help

  1. How to ask for help: help Simple internal: help Command external: command --help or --h
  2. man manul abbreviation, stands for manual. Detailed help, any command, any configuration file can be found in the man document
    1. 1 command (bin)
    2. 5 Configuration file
    3. 8 Administrator-related tool commands and background programs (sbin)
    4. man 1 command
    5. man 5 The name of the configuration file (without adding a path), vsftpd.conf/sshd_config
    6. man 8 shutdown
      Insert picture description here

8. type command

Main function: Check whether a command is an internal command or an external command
Insert picture description here

9. history command

history: Chinese translation, representing history.
Main function: View previously entered Shell command information
Insert picture description here

10. Extension: VMware Tools installation (understand)

10.1 What is VMware Tools

A collection of drivers and utilities

10.2 Install VMware Tools

Step 1: Find the VMware Tools menu, as shown in the figure below:
Insert picture description here
Step 2: Check whether the VMware Tools CD-ROM icon is displayed:
Insert picture description here
Step 3: Open the terminal of the CentOS system (similar to a DOS window)

If you log in to the operating system as a normal user, you must switch To super administrator root

su - root

Step 4: Find the path where VMware Tools is located, usually in the /media directory, enter the ls command to see what files are
Insert picture description here
in the current directory: In Linux systems, if we don’t remember a certain command or a certain path or name , Don’t worry, just enter the first few letters + Tab key, the system will automatically help us complete.
Step 5: Use the cp command to copy the file to the /root directory (in your own home):
Insert picture description here
Step 6: Use the tar command to decompress the .tar.gz file and
Insert picture description here
press Enter!
Insert picture description here
Step 7: Execute the restart command
Insert picture description here

Guess you like

Origin blog.csdn.net/xw1680/article/details/111352147