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