First, the basic format of the Tar Packaging command is introduced, and the following three types cannot be confused.
tar [-j|-z] [CV] [-f new filename] file1 file2 ...;
tar [-j|-z] [TV] [-F new file name]; <== Viewing file names
tar [-j|-z] [XV] [-F new file name] [-C directory]; <== Unpacking
Parameter description:
-C: Create a new package file with-V to see the file names that are packaged in the process
-T: View what file names are included in the contents of a packaged file
-X: Unpack or unzip the function. Can be used with uppercase C to specify the extract directory
----------------------------------------------------------------------------------------------
-J: Recommended for use with BZIP2 compression/decompression.
-Z: Compression/decompression via gzip.
-V: During the compression/decompression process, the file name being processed is displayed.
-F FileName:
-C Directory: Specify extract Directory
First, use tar to add-j or-Z parameter backup:
Tar-jpcv-f/root/etc.tar.bz2/etc;
1, add the parameter-P is to save the original file permissions and properties.
2. The file name saved by default does not have a root directory/for security purposes. Otherwise, the other files may be overwritten when decompressed.
Second, check the contents of the tar file (can see the file name) and the backup file name has no root directory meaning:
Tar-jtv-f/root/etc.tar.bz2;
1, you can see the results shown, each file name does not have a root directory/, this is for security reasons. Because the root directory is represented by the absolute path, the decompression will be covered when the situation.
2. Use the-p (uppercase) parameter if you are sure you want to add a root backup, but this is not recommended.
Three, unzip, and specify the directory:
Tar-jxv-f/root/etc.tar.gz;
Tar-jxv-f/root/etc.tar.gz-c/tmp;
Iv. unzip only a single file:
Tar-jtv-f/root/etc.tar.bz2 |grep ' shadow '; <== Search, follow-up learning
Tar-jxt-f/root/etc.tar.bz2 Etc/shadow;
1. Note that the-C parameter is not added.
2, the basic step is to find the file to extract, determine its filename, here is Etc/shadow, no root directory/.
Five, packaging a directory, but does not include some files under the directory:
Tar-jcv-f/root/etc.tar.bz2--exclude=/root/test*/root; <==--exclude for specifying excluded files
The above command means to package all other files in the/root directory except those that begin with test.
Six, only backup more than a moment of new files:
Tar-jcv-f/root/etc.tar.bz2--newer-mtime= "2008/09/29"/etc/*;
VII. Special Applications: No understanding
Tar-cv-f-etc | Tar-xv-f-;
For the time being, there are 2 commands executed, one for packaging, one for unpacking, and no compression command. The package command does not specify the destination file, the unpacking command does not specify the original file, or both are specified for-.