Compress the directory and its files today:
/usr/local/test
# tar -cvf /usr/local/auto_bak/test.tar /usr/local/test Only packaging, not compression
# tar -zcvf / After usr/local/auto_bak/test.tar.gz /usr/local/test is packaged, the name of the compressed file after the parameter f is compressed by gzip. It is customary to use tar to do it. If the z parameter is added, it is tar.gz or tgz represents a gzip-compressed tar file
Decompression operation:
#tar -zxvf /usr/local/test.tar.gz
tar Detailed explanation of decompression command
-c: Create a compressed archive
-x: Decompress
-t: View the 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 and are used for both compression and decompression One of them 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 the files in the all.tar package, -t means to list the files
# tar -xf all.tar
This command is to extract all. For all files in the tar package, -x means unzip
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 //Unzip rar
unzip file.zip //Unzip zip
Summary
(1), *.tar Use tar –xvf to decompress
(2), *.gz Use gzip -d or Gunzip decompress
(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 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 Decompression
For more detailed explanations of tar decompression commands, please pay attention to the PHP Chinese website for related articles!