Home > php教程 > PHP开发 > body text

Detailed explanation of tar compression and decompression commands under Linux

高洛峰
Release: 2016-12-19 14:13:04
Original
1186 people have browsed it

tar

-c: Create a compressed archive
-x: Decompress
-t: View the content
-r: Append files to the end of the compressed archive
-u: Update the files in the original compressed package

These five are independent One of the commands is 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: Display all processes
-O: Unpack the file to standard output

The following parameter -f It is necessary

-f: Use the file 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 package all .jpg files into a package named all.tar. -c means generating a new package, and -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 adding 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 files in the all.tar package, -t means to list files

# tar -xf all.tar
This command is to extract all. For all files in the tar package, -t means unpacking

compression

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

tar -czf jpg.tar.gz *.jpg //Package all jpg files in the directory into jpg.tar, and compress them with gzip to generate a gzip-compressed package, named jpg.tar.gz

tar -cjf jpg.tar.bz2 *.jpg //Package 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 //Package 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 //For compression in rar format, you need to download rar for linux first

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

Unzip

tar -xvf file.tar //Unzip tar Package

tar -xzvf file.tar.gz //Extract tar.gz

tar -xjvf file.tar.bz2 //Extract tar.bz2

tar -xZvf file.tar.Z //Extract tar.Z

unrar e file.rar //Extract rar

unzip file.zip //Extract zip

Summary

1. Use tar -xvf to decompress *.tar

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

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

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

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

6. *.Z Use uncompress to decompress

7, *.tar.Z Use tar -xZf to decompress

8, *.rar Use unrar e to decompress

9, *.zip Use unzip to decompress



More Please pay attention to the PHP Chinese website for related articles about tar compression and decompression commands under Linux!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template