Common examples of TAR commands under Linux

Source: Internet
Author: User

Syntax: tar [main option + Secondary options] file or directory

When using this command, the main option is required, and it tells Tar what to do, auxiliary options are auxiliary and can be used.

Main options:
C Create a new profile. Select this option if the user wants to back up a directory or some files. Equivalent to packaging.
X release the file from the archive file. Equivalent to unpacking.
T list the contents of the archive file and see which files have been backed up.

Accessibility Options:
-Z: Do you compress or unzip using gzip format? The general format is xxx.tar.gz or xxx.tgz
-J: Do you want to compress or decompress using BZIP2 format? The general format is xxx.tar.bz2
-V: Files are displayed during compression! This common
-F: Use the file name, please note, after F to immediately answer the file name Oh! Don't add any more parameters!
-P: Use original file properties (attributes are not changed according to user)
--exclude=file/dir: In the compression process, do not package the specified file or directory, special attention to think: If you do not package the specified directory, the directory name do not add "/"

The compression operations that we may often use at work are as follows:

 [[email protected]tar -cvf 5201351 . tar /5201351 //  package only, do not compress  [[Email protected]5201351  ~]# tar -zcvf 5201351. tar . gz/5201351 //  after packaging, compress  [[Email protected]5201351  ~]# tar -JCVF 5201351. tar . bz2/5201351 //  after packaging, compress   with bzip2 

When executing the above command, a warning message is displayed:tar:removing leading '/' from member names
That's a special setting for absolute paths. It is not affected by the direct decompression to other directories.

[Email protected]/]#tar cvf 5201351. tar 5201351/--exclude=5201351/aa01   // Packaging does not pack the AA01 directory under 5201351 directories

The usual decompression operations are as follows:

[Email protected] ~]#tar zxvf 5201351. tar. gz-c/opt                   //-c parameter, extract/5201351.tar.gz files to/opt directory [[email protected] ~]#tar ZXVF 5201351. tar. GZ 5201351/5201351.txt       // unzip only 5201351/5201351.txt in 5201351.tar.gz

Common examples of TAR commands under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.