linux/unix tar

tar

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

These five commands are independent, and one of them should be used 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 archives as needed

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

The following parameter -f is required

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

# 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 extract all the files in the all.tar package, -t means unpack

compression

tar -cvf jpg.tar *.jpg //Package 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 gzip compressed package named jpg.tar.gz

 tar -cjf jpg.tar.bz2 *.jpg //Pack all jpg files in the directory into jpg.tar, and compress them 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 it with compress to generate a umcompress compressed package named jpg.tar.Z

rar a jpg.rar *.jpg //Compression in rar format, you need to download rar for linux first

zip jpg.zip *.jpg //Compression in zip format, you need to download zip for linux first

decompress

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

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

tar -xjvf file.tar.bz2 // 解压 tar.bz2

tar -xZvf file.tar.Z //decompress tar.Z

unrar e file.rar // depressurar

unzip file.zip //unzip the zip

Summarize

1. Decompress *.tar with tar -xvf

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

3. Decompress *.tar.gz and *.tgz with tar -xzf

4. Decompress *.bz2 with bzip2 -d or with bunzip2

5. Unzip *.tar.bz2 with tar -xjf

6. *.Z decompress with uncompress

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

8. *.rar decompress with unrar e

9. Unzip *.zip with unzip

Guess you like

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