Compressed file command: tar
Options and parameters:
-c : Create a packaged file, you can use -v to view the filename (filename) packaged in the process
-t : Check which file names are contained in the contents of the packaged file, the key point is to check the "file name";
-x : The function of unpacking or decompressing, which can be unpacked in a specific directory with -C (uppercase)
Special attention is, -c, -t, -x can not appear in a series of instructions at the same time.
-z : compress/decompress with gzip support: the best filename is *.tar.gz
-j : Compress/decompress with bzip2 support: the best filename is *.tar.bz2
-J : compress/decompress with xz support: the best filename is *.tar.xz
Pay special attention, -z, -j, -J cannot appear in a series of command lines at the same time
-v : In the process of compressing/decompressing, display the filename being processed!
-f filename: The filename to be processed should be immediately followed by -f! It is recommended to write an option for -f separately! (comparison will not forget)
-C directory: This option is used for decompression. To decompress in a specific directory, you can use this option.
Other options that will be used in subsequent exercises:
-p (lowercase): retain the original permissions and attributes of the backup data, often used to backup (-c) important configuration files
-P (uppercase): keep the absolute path, that is, allow the root directory to exist in the backup data;
--exclude=FILE: Do not pack FILE during compression!
tar [-z|-j|-J] [cv] [-f new file name to be created] filename... <== package and compress
tar [-z|-j|-J] [tv] [- f existing tar file name] <== view file name tar [-z|-j|-J] [xv] [-f existing tar file name] [-C directory] <== decompress
( --From Brother Bird's private kitchen)
1. Packaged as xxx.tar
e.g.:tar -cvf file.tar file
2. Unpack xxx.tar
e.g: tar -xvf file.tar
3. Package it into a compressed file (ie tarball)
Compression commands are : gzip, bzip2, xz
The suffix of the compressed file is : xxx.gz, xxx.bz2, xxx.xz
Packaging into a compressed file requires 2 steps :
1. First package into xxx.tar
2. Recompress to xxx.tar.{gz|bz2|xz}
However, tar can already complete the above process in one step through the command. The following is only the gzip compression command. The usage of bzip2 and xz is the same:
-z: use gzip command to compress/decompress
-j: compress/decompress using the bzip2 command
-J: compress/decompress using the xz command
-c: compress
-x: decompress
-t: View the contents of the tar file
-v: show the process of compressing or decompressing
(1). Use tar to pack and compress into xxx.tar.gz
Usage: tar -zcvf xxx.tar.gz xxx ... (multiple directories)