Linux tar command

Source: Internet
Author: User

I used it myself before, but I don't need it for a long time. Recently used, it has been found that it cannot be used correctly, so this time record it for later viewing.

 

The tar command is a packaging command for files (folders) in Linux. Packaging means that multiple files (folders) are made up of a collection. In Linux, only one file can be compressed. To Compress multiple files, you must package them first.

Tar uses the following options:

-C (create): Create a new archive.

 

-F: The file name followed by the archive.
-T: displays the list of files included in the TAR file.

-V (verbose)-displays detailed archived information

-X (extract)-extracts files from the archive.
-Z: Use gzip to decompress the tar file.
-J-use Bzip2 to compress the tar file.

 

1. Use tar to package files

Syntax tar-CVF tarname srcname:

Eg: tar-CVF test.tar./Trac-0.12

Enclose the trac-0.12file folder in the preceding directory in the test.tar folder.

 

In the past, only tar-CVF test.tar was used. The following error is reported :"Tar: exercise caution when rejecting the creation of an empty archive file. In this case, tar does not create an empty tar file.

 

2. Compress the packaged files

Gzip test.tar

Compress test.tarand the compressed file name is test.tar.gz.

 

The preceding compressed package can be implemented using a tar command.

Command: tar-CZF test1.tar.gz./Trac-0.12

 

I always thought it was tar-CF tarname, srcname, and tar-ZF tarname. After packaging with the tar command, Compress With the tar-Z option. It's wrong to try for half a day. It can only be tar-CZF tarname or tar-cfTarname srcname. gzip tarname

 

3. Extract A. T file.Ar.gz compressed package

 Gzip-D (decompress) test.tar.gz

Decompress test.tar.gzto test.tar.

 

4.unpack test.tar

Tar-XF test.tar

 

You can use tar to implement the above 3, 4 commands.

Tar-xzf test.tar.gz

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.