The usage of the package compression and unpacking program tar under linux

tar compression method:

tar -zcvf downloads.tar.gz doanloads

tar -zcvf The full path of the file name generated after packaging is the directory to be packaged.
Example: After packaging the downloads folder, a downloads.tar.gz file is generated.

tar decompression method:

tar -zxvf downloads.tar.gz

The following information comes from: https://www.cnblogs.com/eoiioe/archive/2008/09/20/1294681.html

.tar
unpacking: tar xvf FileName.tar
packing: tar cvf FileName.tar DirName
(Note: tar is packing, not compressing!)
———————————————
.gz
unpacking 1: gunzip FileName.gz
decompression 2: gzip -d FileName.gz
compression: gzip FileName

.tar.gz and .tgz
decompression: tar zxvf FileName.tar.gz
compression: tar zcvf FileName.tar.gz DirName
———————————————
.bz2
decompression 1: bzip2 -d FileName .bz2
decompression 2: bunzip2 FileName. bz2
compression: bzip2 -z FileName

.tar.bz2
decompression: tar jxvf FileName.tar.bz2
compression: tar jcvf FileName.tar.bz2 DirName
———————————————
.bz
decompression 1: bzip2 -d FileName.bz
decompression 2: bunzip2 FileName.bz
compression: unknown

.tar.bz
decompression: tar jxvf FileName.tar.bz
compression: unknown
———————————————
.Z
decompression: uncompress FileName.Z
compression: compress FileName
.tar.Z

Decompression: tar Zxvf FileName.tar.Z
Compression: tar Zcvf FileName.tar.Z DirName
———————————————
.zip
decompression: unzip FileName.zip
compression: zip FileName.zip DirName
— ——————————————
.rar
decompression: rar x FileName.rar
compression: rar a FileName.rar DirName
———————————————
.lha
decompression: lha -e FileName.lha
compression: lha -a FileName.lha FileName
———————————————
.rpm
unpacking: rpm2cpio FileName.rpm | cpio -div
——————— ————————
.deb
unpacking: ar p FileName.deb data.tar.gz | tar zxf
-———————————————
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh .lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName

sEx just calls related programs, it has no compression and decompression functions, please pay attention!

The gzip command
has two obvious advantages in reducing file size. One is that it can reduce storage space, and the other is that it can reduce the transfer time when transferring files over the network. gzip is a command often used in Linux systems to compress and decompress files, which is convenient and easy to use.

Syntax: gzip [Options] Compressed (decompressed) file name The meaning of each option of this command is as follows:

-c Write the output to standard output and keep the original file. -d Unzip the compressed file. -l For each compressed file, the following fields are displayed: the size of the compressed file; the size of the uncompressed file; the compression ratio; the name of the uncompressed file -r recursively find the specified directory and compress all files in it or decompress it. -t test to check whether the compressed file is complete. -v For each compressed and decompressed file, display the file name and compression ratio. -num Use the specified number num to adjust the compression speed, -1 or --fast means the fastest compression method (low compression ratio), -9 or --best means the slowest compression method (high compression ratio). The system default value is 6. Examples of instructions:

gzip *% Compress each file in the current directory into a .gz file. gzip -dv *% decompress each compressed file in the current directory and list detailed information. gzip -l *% displays in detail the information of each compressed file in Example 1, without decompressing it. gzip usr.tar% Compresses the tar backup file usr.tar, and the extension of the compressed file is .tar.gz.

The following information comes from: https://www.cnblogs.com/jyaray/archive/2011/04/30/2033362.html

Detailed tar command

-c: create a compressed file

-x: unzip

-t: view content

-r: append files to the end of the compressed archive file

-u: update the files in the original compressed package

These five are independent commands. One of them is required for compression and decompression. It can be used in conjunction with other commands, but only one of them can be used.

The following parameters are optional when compressing or decompressing files according to needs.

-z: with gzip attribute

-j: with bz2 attributes

-Z: with compress attribute

-v: display all processes

-O: Unzip the file to standard output

The parameter -f is required

-f: Use the file name. Remember, this parameter is the last parameter, and only the file name can be followed.

# tar -cf all.tar *.jpg This command will mark all .jpg files into a package named all.tar. -c means to generate a new package, -f specifies the file name of the package.
# tar -rf all.tar *.gif This command adds all .gif files to the all.tar package. -r means adding files. 
# tar -uf all.tar logo.gif This command is to update the logo.gif file in the original tar package all.tar, and -u means to update the file. 
# tar -tf all.tar This command is to list all files in the all.tar package, -t means to list files 
# tar -xf all.tar This command is to extract all the files in the all.tar package, -x means to untie

View
tar -tf aaa.tar.gz View the contents of the compressed package without decompressing

compression

tar --cvf jpg.tar *.jpg //Pack all jpg files in the directory into tar.jpg

tar –czf jpg.tar.gz *.jpg //After packaging all the jpg files in the directory into jpg.tar, and compress it with gzip to generate a gzip compressed package, named jpg.tar.gz

tar –cjf jpg.tar.bz2 *.jpg //After packaging all jpg files in the directory into jpg.tar, and compress it with bzip2, a bzip2 compressed package is generated, named jpg.tar.bz2

tar –cZf jpg.tar.Z *.jpg //After packing all the jpg files in the directory into jpg.tar, and compress it with compress to generate a umcompress compressed package, named jpg.tar.Z

Unzip

tar --xvf file.tar //Unzip the tar package

tar -xzvf file.tar.gz // 解压 tar.gz

tar -xjvf file.tar.bz2 //Unzip tar.bz2tar --xZvf file.tar.Z //Unzip tar.Z

to sum up

1. Decompress *.tar with tar -xvf

2. Decompress *.gz with gzip -d or gunzip

3. Use tar -xzf to decompress *.tar.gz and *.tgz

4. Use bzip2 -d or bunzip2 to decompress *.bz2

5. Use tar -xjf to decompress *.tar.bz2

6. Use uncompress to decompress *.Z

7. Decompress *.tar.Z with tar -xZf

Guess you like

Origin blog.csdn.net/leon_zeng0/article/details/109089444