Linux Command---Tar

Source: Internet
Author: User

file Compression decompression command tar :

1. Tar command-line options

Options Command description
-C Create a compressed archive
-X Extract
--delete Deletes an existing file from a compressed package, and if the file appears more than once in the package, the operation deletes it all.
-T View a list of files in a compressed package
-R Append files to the end of a compressed archive file
-U Update the files in the original compressed package
-Z Compress to gzip format, or unzip in gzip format
-j Compress to BZIP2 format, or extract in bzip2 format
-V Displays the process of compression or decompression, which is generally not suitable for background operations
-F Using the file name, this parameter is the last parameter and can only be followed by the file name.


2. Examples of tar use:
#将当前目录下所有文件压缩打包, it should be explained that many people are accustomed to name the extension of files compressed by the Tar tool. Tar
/> TAR-CVF Test.tar *
-rw-r--r--. 1 root root 183 Nov 08:02 users
-rw-r--r--. 1 root root 279 Nov 08:45 users2

/> cp.  /*.log. #从上一层目录新copy一个 the. log file to the current directory.
/> TAR-RVF test.tar *.log #将扩展名为. log files are appended to the Test.tar package.
/> TAR-TVF Test.tar
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2
-rw-r--r--root/root 48217 2011-11-11 22:16 Install.log

/> Touch Install.log#使原有的文件更新一下最新修改时间
/> TAR-UVF test.tar *.log In #重新将更新后的log文件更新到test. Tar
/> TAR-TVF test.tar #从输出结果可以看出tar包中多出一个更新后install. log file.
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2
-rw-r--r--root/root 48217 2011-11-11 22:16 Install.log
-rw-r--r--root/root 48217 2011-11-11 22:20 Install.log

/> Tar--delete install.log-f test.tar #基于上面的结果, remove Install.log from the compressed package
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2

/> rm-f users users2 #从当前目录将tar中的两个文件删除
/> tar-xvf test.tar #解压
/> ls-l users* #仅列出users和users2的详细列表信息
-rw-r--r--. 1 root root 183 Nov 08:02 users
-rw-r--r--. 1 root root 279 Nov 08:45 users2

#以gzip的格式压缩并打包, decompression should also be extracted in the same format, it should be explained that the format of the package is compressed in the extension after adding. GZ
/> Tar-cvzf test.tar.gz *
    /> TAR-TZVF test.tar.gz #查看压缩包中文件列表时也要加ZOptionsgzipFormat
-rw-r--r--root/root 48217 2011-11-11 22:50 Install.log
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2

/> rm-f users users2 install.log
/> tar-xzvf test.tar.gz#以gzipThe format decompression
/> ls-l *.log users*
-rw-r--r--root/root 48217 2011-11-11 22:50 Install.log
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2

/> rm-f test.*#删除当前目录下原有的压缩包文件
#以bzip2The format of the compression and packaging, decompression should also be extracted in the same format, need to explain that the format of the package is compressed in the extension after the add. bz2
/> TAR-CVJF test.tar.bz2 *
/> tar-tjvf test.tar.bz2#查看压缩包中文件列表时也要加JOptionsbzip2Format
-rw-r--r--root/root 48217 2011-11-11 22:50 Install.log
-rw-r--r--root/root 183 2011-11-11 08:02 Users
-rw-r--r--root/root 279 2011-11-11 08:45 users2

/> rm-f *.log user*
/> tar-xjvf test.tar.bz2#以bzip2The format decompression
/> ls-l
-rw-r--r--. 1 root root 48217 Nov 22:50 Install.log
-rw-r--r--. 1 root root 10530 Nov 23:08 test.tar.bz2
-rw-r--r--. 1 root root 183 Nov 08:02 users
-rw-r--r--. 1 root root 279 Nov 08:45 users2

Linux Command---Tar

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.