table of Contents
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
特别注意: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.
Usage 3: Create multiple directories at the same time.
Syntax: mkdir [-p] Path 1 Path 2 Path 3
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
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
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
Usage 2: Create multiple files at the same time
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
Usage 2: Recursively delete directories
Usage 3: Force delete files or directories
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.
Usage 2: : Copy the /root/shop directory to the /tmp directory
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:
- 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.
- In the process of moving, the name of the document is unchanged, but the path is changed
Cut and move files:
Cut and move folders:
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]
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
Syntax 2: gzip file1 file2 compresses multiple files at the same time. The compression
speed is fast, the compression rate is low, and the cpu overhead is relatively low.
Decompression: gunzip or gzip -d
☆ bzip2 command
compression: bzip2 needs to be compressed File
decompression: bzip2 -d files that need to be decompressed have
slow 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
Decompression: unxz or xz -d
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 tar
to 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:
- -c, the meaning of create
- -v, the meaning of visualization, that is, you can view the creation process, you can omit
- -f, required parameter, cannot be omitted
- u, the abbreviation of update, update the file in the original package file (understand)
- r, append meaning, append a file to the end of the compressed archive file (understand)
- -t, view the contents of the packaged file (understand)
Add the readme.txt file to the test.tar package. -r means adding files. as follows:
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:
- -z, compressed to .gz format
- -j, compressed to .bz2 format
- -J, compressed to .xz format
- c, the meaning of create
- v, the meaning of visualization, that is, you can view the creation process, you can omit
- 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
Compress hello.txt and world.txt into test.tar.xz files
4.2.3 Unzip
When decompressing, replace c in the compression command with x to
decompress the test.tar.gz file.
Decompress the test.tar.xz file.
Use the option -tf to view the contents of the compressed file, and all three formats of compressed files are applicable.
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
Usage 2: Folder compression
(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.
Usage 2: decompress to the specified directory
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
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
5.3 View in reverse order
Command: tac
Function: View file content in reverse order
Syntax: tac file name
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 输出重定向技术
.
>
: Standard output redirection ⇒ overwrite output, the original file content will be overwritten>>
: 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
Usage 2: echo command, function: string output
Usage 3: use echo command to write custom content to the file
6.1 Extension: standard input and output
I/O input and output of bash:
- Standard input (stdin): the content entered on the keyboard file descriptor ⇒ 0
- Standard output (stdout): the correct result file descriptor output on the screen ⇒ 1
- Standard error (stderr): The result of the error output on the screen. File descriptor ⇒ 2
- Standard error redirect
- &>: Standard output and standard error redirection
7. Help
- How to ask for help: help Simple internal: help Command external: command --help or --h
- man manul abbreviation, stands for manual. Detailed help, any command, any configuration file can be found in the man document
- 1 command (bin)
- 5 Configuration file
- 8 Administrator-related tool commands and background programs (sbin)
- man 1 command
- man 5 The name of the configuration file (without adding a path), vsftpd.conf/sshd_config
- man 8 shutdown
8. type command
Main function: Check whether a command is an internal command or an external command
9. history command
history: Chinese translation, representing history.
Main function: View previously entered Shell command information
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:
Step 2: Check whether the VMware Tools CD-ROM icon is displayed:
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
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):
Step 6: Use the tar command to decompress the .tar.gz file and
press Enter!
Step 7: Execute the restart command