There are many instructions for compressing and decompressing files and directories in the Linux operating system
There are many file and directory compression formats, such as the following:
.zip /.tar /.tar.gz /.tar.bz2 / .gz
The following summarizes the compression and decompression instructions for each format:
1 Compression/decompression instructions and usage of files ending in .zip
For example existing file:haoxuesheng.zip
Unzip the compressed file ending in .zip: unzip haoxuesheng.zip
Compress the folder to get the compression instructions of the compressed package ending in .zip: zip -r -v haoxuesheng.zip haoxuesheng
in:
-s
means to include hidden files when compressing
-r
It is to recursively compress all files and directories in the directory. If there is no such instruction, the directory will be compressed successfully, but the file after the successful compression is empty, because all the files in it are not recursively compressed.
-v
Refers to the execution process of the display command
[In Linux, the default is to display the execution process of the command]
When the file directory is compressed, the entire process will be displayed
-q
Do not display the execution process of the command
This command will close the information that appears when the directory is compressed. If the file directory is large, the program will click a little after the command is typed to indicate the consumption of the compression process.
2 Compression/decompression instructions and usage of files ending with .tar / .tar.gz / .tar.bz2
We have seen many names of compressed packages ending with tar. in the Linux system, and there are many parameter options for viewing tar. The common options are as follows:
-c: Create a new archive file (Create)
-x: Extract files from an archive file (eXtract)
-t: List the contents of an archive file (lisT)
-v: Display detailed information about tar command execution (Verbose)
- f: Specify the name of the archive file (File)
-z: Use the gzip compression algorithm to compress or decompress (gzip) when creating or extracting the archive file
-j: Use when creating or extracting the archive file bzip2 compression algorithm to compress or decompress (bzip2) used in tar.gz
For the most part, x is for extraction or decompression, z and j are for compression, and other parameters are just icing on the cake.
Be sure to flexibly adapt the parameters
Next, let's start talking about compressed files ending in .tar
Unzip a compressed file ending in .tar: tar -xvf haoxuesheng.tar
Compress the folder to get the compression instructions of the compressed package ending with .tar: tar -zcvf haoxuesheng.tar haoxuesheng
Of course, you can use it tar -zcf haoxuesheng.tar haoxuesheng
without any problem.
Extract the compressed .tar.gz file: tar -zxvf haoxuesheng.tar.gz
Compress the folder to get the compression instructions of the compressed package ending in .tar.gz: tar -zcvf haoxuesheng.tar.gz haoxuesheng
Extract the compressed .tar.bz file: tar -jxvf haoxuesheng.tar.gz
Compress the folder to get the compression instructions of the compressed package ending in .tar.bz: tar -jcvf haoxuesheng.tar.bz haoxuesheng
3 Compression/decompression instructions and usage of files ending in .gz
Unzip the .gz archive: gunzip haoxuesheng.gz
Compress the file to get the compression instructions of the compressed package ending in .gz: gzip haoxuesheng
Please note that gzip can only compress files but not directories, not as good as zip can compress both directories and files
And gzip compression does not need to specify the compressed package name
Although the parameter -r can also be added like zip, it can only compress files in all directories, not directories. When you use the gzip file package name for a file package, you will find that the file directory is not compressed, and all the files inside are compressed into compressed files with the .gz suffix format, and all directories are not compressed. All files are compressed
Then this kind of ending compression is generally not commonly used, just understand it