Use of the TAR packaging tool

Source: Internet
Author: User

Zip compressed file

Zip Compress, the original file will not be deleted after compressing the file

[[email protected] mulu]# zip wen.txt.zip wen.txt     zip  压缩命名   要压缩的文件  adding: wen.txt (deflated 73%)[[email protected] mulu]# ll -h总用量 3.7M-rw-r--r-- 1 root root 2.9M 6月 21 15:54 wen.txt-rw-r--r-- 1 root root 783K 6月 24 12:54 wen.txt.zip

Zip archive directory

[[email protected] tmp]# zip -r mulu.zip 1.txt mulu/        -r指定压缩目录的选项  adding: 1.txt (stored 0%)  adding: mulu/ (stored 0%)  adding: mulu/wen.txt (deflated 73%)  adding: mulu/wen.txt.zip (stored 0%)[[email protected] tmp]# ll -h         压缩目录和文件后总用量 1.6M-rw-r--r-- 1 root root 0 6月 24 12:57 1.txtdrwxr-xr-x 2 root root 40 6月 24 12:54 mulu-rw-r--r-- 1 root root 1.6M 6月 24 12:57 mulu.zip

Zip decompression

[[email protected] tmp]# unzip mulu.zip Archive: mulu.zip     

Zip does not support viewing content within a compressed file, but you can see what files are in a compressed package and use Unzip-l to view

[[email protected] tmp]# unzip -l mulu.zip Archive: mulu.zip  Length Date Time Name--------- ---------- ----- ----        0 06-24-2018 12:57 1.txt        0 06-24-2018 12:54 mulu/  3017434 06-21-2018 15:54 mulu/wen.txt   800798 06-24-2018 12:54 mulu/wen.txt.zip--------- -------  3818232 4 files
Tar Packaging tools

TAR-CVF Packaging The contents of the name to be packaged
TAR-XCF Package Name
TAR-TF Package Name View the number of files inside a packaged file
TAR-CVF Package name--exclude 1.txt directory to package/package a directory exclude specified files from being packaged

[[email protected] tmp]# tar -cvf mulu.tar mulu  mulu/mulu/wen.txtmulu/wen.txt.zip[[email protected] tmp]# ll -h总用量 5.2M-rw-r--r-- 1 root root 0 6月 24 12:57 1.txtdrwxr-xr-x 2 root root 40 6月 24 13:00 mulu-rw-r--r-- 1 root root 3.7M 6月 24 13:11 mulu.tar-rw-r--r-- 1 root root 1.6M 6月 24 12:57 mulu.zip[[email protected] tmp]# tar -xvf mulu.tar mulu/mulu/wen.txtmulu/wen.txt.zip[[email protected] tmp]# tar -tf mulu.tar    查看打包文件内的文件信息 mulu/mulu/wen.txtmulu/wen.txt.zip[[email protected] tmp]# tar -cvf mu.tar --exclude 1.txt mulu /打包一个目录排除掉指定文件mulu.tarmulu.zip
Package and Compress

TAR-ZCF Compressed Package Name the directory/file to be compressed is compressed in zip format
The tar-z position is in the specified compression format, and z is represented as gzip,j for bzip2,-c compression,-X decompression

Tar is a very extensive document packaging format used in Linux. The advantage is that it consumes very little CPU and time to package files, but it is just a packaging tool and is not responsible for compression. Here's how to package a directory:

[[email protected] ]# tar -cvf archive_name.tar directory_to_compress

Here is how to unpack the command:

[[email protected] ]# tar -xvf archive_name.tar.gz

This unpacking command will unlock the document under the current directory. Of course, you can also use this command to change the path of the unpacking:

[[email protected] ]# tar -xvf archive_name.tar -C /tmp/extract_here/

Tar.gz it does not take up too much CPU when compressing, and it can get a very ideal compression rate. You can use the following command to compress a directory:

[[email protected] ]# tar -zcvf  archive_name.tar.gz  directory_to_compress

tar.gz Decompression:

[[email protected] ]# tar -zxvf archive_name.tar.gz

The above unpacking command will unzip the document under the current directory. Of course, you can also use this command to change the path of the unpacking:

[[email protected] ]# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

tar.bz2

This compression format is the best compression rate in all ways. This, of course, means that it consumes more CPU and time than the previous way. The following command is how to use tar.bz2 for compression.

[[email protected] ]# tar -jcvf archive_name.tar.bz2 directory_to_compress

This unpacking command will unlock the document under the current directory. You can also use this command to change the path of the unpacking:

[[email protected] ]# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/
下面对tar命令中一些常用重要的参数进行总结:-c或–create 建立新的备份文件。 -C<目的目录>或–directory=<目的目录> 切换到指定的目录。 -f<备份文件>或–file=<备份文件> 指定备份文件。 -j或–bzip2 以bz2的算法来压缩或者解压文件。 -k或–keep-old-files 解开备份文件时,不覆盖已有的文件。 -m或–modification-time 还原文件时,不变更文件的更改时间。 -N<日期格式>或–newer=<日期时间> 只将较指定日期更新的文件保存到备份文件里。 -r或–append 新增文件到已存在的备份文件的结尾部分。 -t或–list 列出备份文件的内容。 -u或–update 仅置换较备份文件内的文件更新的文件。 -v或–verbose 显示指令执行过程。 -w或–interactive 遭遇问题时先询问用户。 -W或–verify 写入备份文件后,确认文件正确无误。 -x或–extract或–get 从备份文件中还原文件。 -z或–gzip或–ungzip 通过gzip指令处理备份文件。 -Z或–compress或–uncompress 通过compress指令处理备份文件。

Use of the TAR packaging tool

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.