Linux Command tar, linux Command tar

Source: Internet
Author: User

Linux Command tar, linux Command tar

The tar command is a reliable method for backing up files in Unix/Linux systems. It can work in almost any environment and has the permission of all users.

Syntax:

Tar [main option + auxiliary option] file or directory
Main options:
C. Create a new archive file. (Package) x release the file from the archive file. (Unpacking) t the primary option for listing the archive content can only exist at the same time
Auxiliary options:
Zgzip format, which is generally the jbzip2 format for files suffixed with gz, generally, the FILE v with the suffix bz2 shows the command execution process. f use the archive name p to use the original attributes of the original FILE (this will not be used in seclusion). -- exclude FILE during compression, do not package files


Example:
Package all the files in the/etc directory into/tmp/etc.tar.
Tar-cvf/tmp/etc.tar/etc <= package only, do not compress! Tar-zcvf/tmp/etc.tar.gz/etc <= compressed by gzip tar-jcvf/tmp/etc.tar.bz2/etc <= compressed by bzip2 # Note, we use the File file name after parameter f. tar. # If the z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~ # If you add the j parameter, use .tar.bz2 as the file name ~ # When the preceding command is executed, a warning message is displayed: # "tar: Removing leading '/" from member names ", which is a special setting for absolute paths.


Check the files in the/tmp/etc.tar.gz File above.
Tar-ztvf/tmp/etc.tar.gz # Because gzip is used for compression, when you want to check the files in the tar file, # Add the z parameter! This is important!

Decompress the/tmp/etc.tar.gz file under/usr/local/src.
Cd/usr/local/srctar-zxvf/tmp/etc.tar.gz # by default, We can unbind the compressed file anywhere! In this example # first, I will change the working directory to the/usr/local/src directory, if/tmp/etc.tar.gz # is unlocked, the directory is stored in/usr/local/src/etc. If you enter/usr/local/src/etc #, you will find that, the file attributes in this directory may be different from/etc!

Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
Cd/tmptar-zxvf/tmp/etc.tar.gz etc/passwd # I can check the file name in the tarfile through tar-ztvf. If you only need one file, # You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!

Back up/home,/etc, but do not/home/dmtsai
tar --exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc

Decompress the package to the specified directory.
tar -zxvf /home/images.tar.gz -C /specific



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.