pack
Command:[ root@localhost ~]#tar [options] source file or directory Common: tar -cvf
option | meaning |
---|---|
-c | Package multiple files or directories. |
-A | Append the tar file to the archive file. |
-f package name | Specifies the file name of the package. The package extension is used to identify the format for the administrator, so you must specify the extension correctly; |
-v | Display the process of packaging files; |
Instances: packaging files
#Format: tar -cvf target file (TAR) original file
[root@VM-4-17-centos ~]# tar -cvf a.tar a.txt
Instances: packaging folders
The same as the packaged file
[root@VM-4-17-centos ~]# tar -cvf databack.tar ./databack
Example: package multiple files and directories into a tar file
[root@VM-4-17-centos ~]# tar -cvf page.tar a.txt ./databack a.txt ./databack/ ./databack/de178_11.sql ./databack/0910running2.sql ./databack/testa_091901.sql ./databack/running2_0919.sql ./databack/dataall0919.sql ./databack/09102.sql
The above is the packaging, which is different from Windows. In fact, it has not been compressed
zip compression and decompression
zip compression
Zip [options] compressed package name source file or source directory list Common: zip -rv Package compressed folder
option | meaning |
-r | Recursively compress the directory, and compress all files and subdirectories under the specified directory. |
-m | After compressing the file, deleting the original file is equivalent to moving the file to the compressed file. |
-v | Displays detailed compression process information. |
-q | The execution process of the command is not displayed during compression. |
-Compression level | The compression level is a number from 1 to 9, - 1 means faster compression speed and - 9 means better compression effect. |
-u | Update the compressed file, that is, add a new file to the compressed file. |
Case: compressing multiple files
[root@VM-4-17-centos ~]# zip all.zip a.sh b.sh c.sh adding: a.sh (deflated 24%) adding: b.sh (stored 0%) adding: c.sh (deflated 70%)
Case: compressed directory is processed recursively with - r
[root@VM-4-17-centos ~]# zip -r databackzip.zip ./databack adding: databack/ (stored 0%) adding: databack/de178_11.sql (deflated 76%) adding: databack/0910running2.sql (deflated 70%) adding: databack/testa_091901.sql (deflated 70%) adding: databack/running2_0919.sql (stored 0%) adding: databack/dataall0919.sql (deflated 78%) adding: databack/09102.sql (deflated 78%)
Unzip unzip
#unzip [options] zip package name
option | meaning |
-d directory name | Unzip the compressed file to the specified directory. |
-n | Decompressing does not overwrite existing files. |
-o | When decompressing, the existing files are overwritten without user confirmation. |
-v | View the details of the compressed file, including the file size, file name and compression ratio contained in the compressed file, but do not decompress. |
-t | Test the compressed file for damage, but do not unzip it. |
-x file list | Unzip the file, but do not include the file specified in the file list. |
Common case: unzip the compressed package to the specified directory Use: - d
[root@VM-4-17-centos ~]# unzip -d ./una/ all.zip
gzip compression and decompression
gzip compression * gizip can only compress files, not directories
gzip [options] source file
option | meaning |
---|---|
-c | Export compressed data to standard output and keep the source file. |
-d | Decompress the compressed file. |
-r | Recursively compress all files in the specified directory and subdirectories. |
-v | For each compressed and decompressed file, the corresponding file name and compression ratio are displayed. |
-l | For each compressed file, the following fields are displayed:
|
-Number | Used to specify the compression level, - 1 has the lowest compression level and the worst compression ratio- 9. The compression ratio is the highest. The default compression ratio is - 6. |
Case 1: file compression
# gzip page.tar
Case 2: preserve source file compression
# gzip -c a.tar>a01.tar.gz
gunzip decompression
#gunzip [options] file
option | meaning |
---|---|
-r | Recursive processing, decompress all files in the specified directory and subdirectory. |
-c | Output the decompressed file to the standard output device. |
-f | Forcibly decompress the file regardless of whether the file already exists. |
-l | Lists the contents of the compressed file. |
-v | Displays the command execution process. |
-t | Test whether the compressed file is normal, but do not decompress it |
Direct decompression:
# gunzip databack.tar.gz