Simple compression-related operations under Linux

Source: Internet
Author: User
Tags tmp file

First, demand: Compression /data to/ tmp

Operation:

1 [[email protected]/]# tar zcf/tmp/data.tar.gz data/                           #压缩/data to/TMP and name the compressed package data.tar.gz 2 [[ Email protected]/]# ls-lrt/tmp/                                            #查看/tmp file 3 total 0 4-rw-r--r--  1 root     Root  490:wuyi data.tar.gz                    #成功

Second, demand: View the contents of the compressed package data.tar.gz

Operation:

 1[Email protected]/]# tar tf/tmp/data.tar.gz #查看压缩包data. tar.gz content, below is the content (contains directories, files, and files under subdirectories)2data/3data/logs/4data/logs/access.log-20170426 5data/logs/access.log-20170430 6data/logs/access.log-20170427 7data/logs/access.log-20170505 8data/logs/access.log-20170429 9data/logs/access.log-20170425Tendata/logs/access.log-20170424 Onedata/logs/access.log-20170503 Adata/logs/Access.log -data/logs/access.log-20170101 -data/logs/access.log-20170508 thedata/logs/access.log-20170428 -data/logs/access.log-20170507 -data/logs/access.log-20170504 -data/logs/access.log-20170422 +data/logs/access.log-20170501 -data/logs/access.log-20170423 +data/logs/access.log-20170502 Adata/logs/access.log-20170506 atdata/Hello.txt -Data/nginx.conf

Third, the need: Unzip the package data.tar.gz to its directory

Operation:

1 [[email protected]/]# tar xf/tmp/data.tar.gz

Iv. needs: Decompression package data.tar.gz to/root

Operation:

1 [[email protected]/]# tar xf/tmp/data.tar.gz-c/root

V. Requirements: Compress /data to/ tmp , but do not include (exclude) hello.txt This file

Operation:

1 [[email protected]/]# tar zcf/tmp/data_pc.tar.gz data/--exclude=hello.txt                      #使用--exclude parameter exclusions hello.txt

VI. requirements: Compress /data to/ tmp , but do not include (exclude) the hello.txt;nginx.conf of these two files (excluding multiple files)

Operation:

1 [[email protected]/]# cat>>paichu.txt<<EOF #将hello. txt;nginx.conf Two File name written to Paichu.txt 2 > hello.txt3 > nginx.conf4 > EOF  5 [[email protected]/]# tar zcf/tmp/data_pc2.tar.gz data/--exclude-from =paichu.txt    # Use--ecclude-from to exclude files in Paichu.txt

Summarize:

Use the tar command to compress and decompress as follows:

    1. Zip file: tar zcf [Compressed package path] [directory/file relative path to compress]
    2. View compressed files: Tar tf [compressed package path]
    3. Unzip the zip file: Tar XF [zipped package Path]
      1. Unzip to the specified path: Tar XF [Compressed package path]-c [Unzip Path]
    4. Compress a directory but exclude one of the files: tar zcf [Compressed package path] [to compress directory relative path]--exclude=[the relative path of the file name of the excluded files]
    5. Compress a directory but exclude multiple files from it:
      1. Create a text file Paichu.txt and write the name of the file you want to exclude.
      2. Then execute: Tar ZCF [Compressed package path] [to compress directory relative path]--exclude-from=[paichu.txt]

----------------------------------------------------Split Line------------------------------------------------------

Reference:

    1. Li Ling Teacher Classes
    2. Http://man.linuxde.net/tar

Simple compression-related operations under Linux

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.