Linux tar command [go]

Source: Internet
Author: User
Tags rar

I. Introduction of use 1, noun distinction

Package: Make a whole bunch of files or directories into a total file "tar command"

Compression: Convert a large file into a small file "gzip,bzip2" through some compression algorithms

Many of the compressors in Linux can only be compressed for one file, so when you want to compress a lot of files, you have to make the whole bunch of files into a package (tar command), and then compress the program (gzip bzip2 command).

2. Tar syntax

Syntax: tar [main option + Secondary options] file or directory

When using this command, the main option must have, which tells Tar what to do, auxiliary options are auxiliary, can be used.

Main option: "One command the following 5 parameters can only have one"

-C:--create Create a new compressed document, which is packaged

-X:--extract,--get unzip file

-T:--list, view everything in the compressed document

-r:--append appending files to a compressed document

-u:--update updating files in the original compressed package

Accessibility Options:

-Z: Do you have the properties of gzip at the same time? Do you need to compress or decompress with gzip? The general format is xxx.tar.gz or xx.tgz

-j: Do you have bzip2 properties at the same time? Is it necessary to compress or decompress with bzip2? The general format is xx.tar.bz2

-V: Show the operation process! This parameter is very common

-F: Use the document name, note that after f you need to immediately answer the document name, no additional parameters!

-C: Switch to the specified directory

--exclude file: Do not package file during compression

Second, example 1, packaging

It is customary to use the. tar suffix to represent the tar package, using xxx.tar.gz or. tgz to represent gzip compressed tar files, using the. tar.bz2 to represent bzip2 compressed tar files.

Package IMG1 and Img2 two folders as Img.tar, only packaged without compression

[Email protected]:~/test$ tar-cvf Img.tar img1 img2img1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105.pngimg2/ 104.pngimg2/103.png[email protected]:~/test$ lsimg1  img2  Img.tar

Package IMG1 and Img2 two folders into img.tar.gz, and after packaging, compress with gzip

[Email protected]:~/test$ tar-zcvf img.tar.gz img1 img2img1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105. Pngimg2/104.pngimg2/103.png[email protected]:~/test$ lsimg1  img2  img.tar  img.tar.gz

Package IMG1 and Img2 two folders into img.tar.bz2, and after packaging, compress them in bzip2

[Email protected]:~/test$ tar-jcvf img.tar.bz2 img1 img2img1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105. Pngimg2/104.pngimg2/103.png[email protected]:~/test$ lsimg1  img2  img.tar  img.tar.bz2  img.tar.gz
2, without pressure to view the case

View all content in the Img.tar

[Email protected]:~/test$ tar-tf img.tarimg1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105.pngimg2/104. Pngimg2/103.png

View all content of img.tar.gz

Plus-v parameter view details,-Z Optional

[Email protected]:~/test$ tar-tf img.tar.gzimg1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105.pngimg2/104. Pngimg2/103.png[email protected]:~/test$ TAR-ZTF img.tar.gzimg1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/ 105.pngimg2/104.pngimg2/103.png[email protected]:~/test$ TAR-ZTVF img.tar.gzdrwxrwxr-x Liuxiaoyan/liuxiaoyan 0 2015-05-20 22:09 img1/-rw-r--r--Liuxiaoyan/liuxiaoyan 1952 2015-05-20 22:08 img1/102.png-rw-r--r--liuxiaoyan/ Liuxiaoyan 2344 2015-05-20 22:08 img1/101.png-rw-r--r--Liuxiaoyan/liuxiaoyan 1995 2015-05-20 22:09 img1/100. Pngdrwxrwxr-x Liuxiaoyan/liuxiaoyan    0 2015-05-20 22:10 img2/-rw-r--r--Liuxiaoyan/liuxiaoyan 1922 2015-05-20 22:09 img2/105.png-rw-r--r--Liuxiaoyan/liuxiaoyan 1546 2015-05-20 22:08 img2/104.png-rw-r--r--Liuxiaoyan/liuxiaoyan 2033 2015-05-20 22:08 Img2/103.png

View IMG.TAR.BZ2 Content

Plus-v parameter view details,-j optional

[Email protected]:~/test$ tar-tf img.tar.bz2 img1/img1/102.pngimg1/101.pngimg1/100.pngimg2/img2/105.pngimg2/104. Pngimg2/103.png[email protected]:~/test$ TAR-JTF img.tar.bz2  img1/img1/102.pngimg1/101.pngimg1/100.pngimg2/ Img2/105.pngimg2/104.pngimg2/103.png[email protected]:~/test$ TAR-JTVF img.tar.bz2 drwxrwxr-x Liuxiaoyan/liuxiaoyan 0 2015-05-20 22:09 img1/-rw-r--r--Liuxiaoyan/liuxiaoyan 1952 2015-05-20 22:08 img1/102.png-rw-r--r--liuxiaoyan/ Liuxiaoyan 2344 2015-05-20 22:08 img1/101.png-rw-r--r--Liuxiaoyan/liuxiaoyan 1995 2015-05-20 22:09 img1/100. Pngdrwxrwxr-x Liuxiaoyan/liuxiaoyan    0 2015-05-20 22:10 img2/-rw-r--r--Liuxiaoyan/liuxiaoyan 1922 2015-05-20 22:09 img2/105.png-rw-r--r--Liuxiaoyan/liuxiaoyan 1546 2015-05-20 22:08 img2/104.png-rw-r--r--Liuxiaoyan/liuxiaoyan 2033 2015-05-20 22:08 Img2/103.png
3. Decompression

Decompression Img.tar to the temp directory

[Email protected]:~/test$ cd temp/[email protected]:~/test/temp$ ls[email protected]:~/test/temp$ tar-xf. /img.tar[email protected]:~/test/temp$ lsimg1  img2

Only IMG1 in the decompression Img.tar

[Email protected]:~/test/temp$ tar-xf. /img.tar Img1[email protected]:~/test/temp$ LSIMG1
4. Update

Now create a new file Movie2.txt under the movies file and update the Enjoy.tar

$ TAR-CF Img.tar img1 Img2 added a photo to IMG1, now update img.tar$ Tar-uf Img.tar img1 with the following command
5. Append
$ TAR-CF Img.tar img1 Img2
Add a folder to the Img.tar img3$ tar-rf Img.tar img3
6,-C parameters

-C (large C parameter is useful, change file directory, multi-layer)-C,--directory=dir changes to directory DIR

Use the-c parameter to change directory to-C after the directory, whether in packaging or decompression is very useful.

Usage: Tar temp.tar file -C filedir

$ cd temp$ lsimg1  img2  img3$ tar-cf Img.tar temp/* This package will also pack the TEMP directory, using the command with the-c parameter below to remove the path information
$ TAR-CF Img.tar *-C TEMP

Extract Img.tar to the temp directory in the current directory

-C Temp
Iii. Summary of Decompression methods

1, *. tar with tar–xvf decompression

2, *.gz with gzip-d or gunzip decompression

3, *. tar.gz and *.tgz with tar–xzf decompression

4, *.bz2 with bzip2-d or with BUNZIP2 decompression

5, *. tar.bz2 decompression with TAR–XJF

6, *. Z Extract with Uncompress

7, *. tar. Z Extract with Tar–xzf

8, *.rar with Unrar x decompression

9, *.zip with unzip decompression

use Unrar Note :

Install Unrar first and use Unrar without parameters to see the help information.

If a file S.rar, there are 1000 songs, with the e parameter, the 1000 songs directly to the full decompression out to the current directory.

If the x parameter is extracted, all content is placed in a folder with the same name.

Resources Link:

Compressed packaging of common Linux commands (gzip, gunzip, tar, zip, bzip2)

One Linux command per day: Tar command

Reprint http://www.cnblogs.com/starof/p/4229017.html

Linux tar command [go]

Related Article

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.