The tar command is used to handle packaging and package settlement. The following commands are commonly required:
1. Unpack:
# tar -zxvf file.tar.gz
The preceding command decompress the package to the current directory. If you extract the package to another directory, use
# tar -zxvf file.tar.gz -C path
Path indicates the directory to which the files are extracted.
2. Packaging:
# tar -zcvf file.tar.gz path
File.tar.gz is the package name, while path is the package's target file path.
Note:
- The parameter V is used to display the packaged file information. If the package is not displayed, no additional information is required.
- The Parameter Z is the format of compression and decompression, and the general suffix is GZ. If you see the suffix gz2, replace the parameter Z with J.
3. view the compressed files.
# tar -tf file.tar.gz
4. In/home, a new file is backed up only when it is earlier
# tar -N "2012/05/30" -zcvf home.tar.gz /home
5. Back up home And/ECT, but do not back up the/home/Dante directory
# tar --exclude /home/dante -zcvf myfile.tar.gz /home/* /etc
6. Package/etc and decompress it to/tmp without generating compressed documents.
# tar -zcvf - /etc | tar -zxvf - -C /tmp
This action is a bit like CP-r/etc/tmp is still useful! Note that the output file is changed to-, the input file is also changed to-, and another | exists. This represents standard output, standard input, and pipeline commands respectively!