Linux various compression, decompression

tar
-c: create a compressed archive
-x: decompress
-t: view the content
-r: append a file to the end of the compressed archive
-u: update the files in the original compressed package

These five are independent commands, which are used for compression and decompression One of them can be used with other commands but only one of them can be used. The following parameters are optional when compressing or decompressing archives as needed.

-z: with gzip attribute
-j: with bz2 attribute
-Z: with compress attribute
-v: show all processes
-O: unpack file to standard output

The following parameters -f are required

-f: use archive Name, remember, this parameter is the last parameter, and can only be followed by the file name.

# tar -cf all.tar *.jpg
This command is to type 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 is to add all .gif files to the all.tar package. -r means to add files.

# tar -uf all.tar logo.gif
This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file.

# tar -tf all.tar
This command is to list all the files in the all.tar package, -t means to list the files

# tar -xf all.tar
This command is to unpack all the files in the all.tar package, -x means unpack

Compress
tar –cvf jpg.tar *.jpg //Pack all jpg files in the directory into tar.jpg
tar –czf jpg.tar .gz *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with gzip to generate a gzipped package named jpg.tar.gz
tar –cjf jpg.tar.bz2 *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with bzip2 to generate a bzip2-compressed package named jpg.tar.bz2
tar –cZf jpg.tar.Z *. jpg //Pack all jpg files in the directory into jpg.tar, and compress them with compress to generate a umcompress compressed package named jpg.tar.Z
rar a jpg.rar *.jpg //rar format For compression, you need to download rar for linux
zip jpg.zip *.jpg //For zip format compression, you need to download zip for linux first.

Unzip
tar –xvf file.tar //Unzip the tar package
tar -xzvf file.tar.gz / /decompress tar.gz
tar -xjvf file.tar.bz2 //decompress tar.bz2
tar –xZvf file.tar.Z //decompress tar.Z
unrar e file.rar //decompress rar
unzip file.zip //decompress zip

Summary
1. Decompress *.tar with tar –xvf2
, *.gz decompress with gzip -d or gunzip3, *.tar.gz
and *.tgz decompress with tar –xzf4
, *.bz2 use bzip2 -d or use bunzip2 decompresses
5, *.tar.bz2 decompresses with tar -xjf
6, *.Z decompresses with uncompress
7, *.tar.Z decompresses with tar -xZf
8, *.rar decompresses with unrar e
9, *.zip uses unzip decompress

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124183&siteId=291194637