Linux tar add and decompress

tar:
tar is not a compression software, but a packaging software, which is to package a file or folder into a file, which is convenient for file backup and archiving, usually with an extension of tar.
# tar -cvf test.tar test ----Package the test folder into test.tar. As can be seen from the figure below, there is no change in the size of test and test.tar, indicating that tar only packages the files.
# tar -xvf test.tar ---- Disassemble test.tar and extract files from it
# tar -tvf test.tar ---- List the contents of the tar package
# tar -rf test.tar log/ -- --Append the log folder to test.tar

zip and unzip:
This is a pair of commands, zip is compressed, unzip is decompressed, and the extension is .zip after compression
# zip test.zip test/ ----- Compression, it can be a file or a folder
# unzip test.zip ----- decompression

tar

tar is mainly used to create archive files, and decompress archive files, it has no compression function, but can call gzip, bzip2 Compression is performed.
Parameter explanation:
    -c create archive
    -x decompress archive
    -v display process
    -f target file, which must be followed by target file
    -j call bzip2 for decompression
    -z call gzip to decompress
    -t list the files in the archive

    $ tar -cvf filename.tar . ### Archive all files in the current directory, but do not compress, note that there is a '.' behind, which cannot be omitted, representing the current The meaning of the directory 
    $ tar -xvf filename.tar ### Extract filename.tar to the current folder
    $ tar -cvjf filename.tar.bz2 . ### Compress using bzip2
    $ tar -xvjf filename.tar.bz2 ### Extract filename.tar.bz2 to current folder
    $ tar -cvzf filename.tar.gz ### Compress with gzip
    $ tar -xvzf filename.tar.gz ### Extract filename.tar.gz to current folder
    $ tar -tf filename ### Only view files in the filename archive, do not decompress Compress

the directory and its files:
/usr/local/test

# tar -cvf /usr/local/auto_bak/test.tar /usr/local/test Only package , without compression
# tar -zcvf /usr/local/auto_bak/test.tar.gz /usr/local/test After packaging, the compressed file name after the parameter f compressed by gzip is taken by yourself. It is customary to use tar to do it. If you add z parameter,

then use tar.gz or tgz to represent the gzip compressed tar file.

Decompression operation:
#tar -zxvf /usr/local/test.tar.gz

tar decompression command detailed
-c: Create compressed archive
-x: Decompression
-t: View the content
-r: Append a file to the end of the compressed archive file
-u: Update the files in the original compressed package

These five are independent commands, one of which must be used for compression and decompression, and can be used in conjunction with other commands but Only use one of them. 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 extract all the files in the all.tar package, -x means
unzip compress

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 After it becomes 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 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 Then, compress it 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

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

Decompress

tar –xvf file.tar //decompress 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), *.tar decompress with tar -xvf
  (2), *.gz decompress with gzip -d or gunzip
  (3 ), *.tar.gz and *.tgz with tar –xzf
  (4), *.bz2 with bzip2 -d or bunzip2
  (5), *.tar.bz2 with tar –xjf
  (6), * .Z is decompressed with uncompress
  (7), *.tar.Z is decompressed with tar –xZf
  (8), *.rar is decompressed with unrar e
  (9), *.zip is decompressed with unzip

Guess you like

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