Analysis of tar command parameters in Linux

Source: Internet
Author: User
Tags gz file

Here, we only describe some common parameters, which are not commonly used here. tar is a command that combines package, unpackage, compression, and decompression.

Usage: tar [option...] [file]...

GNU 'tar'

Saves many files together to a separate tape or disk archive, and can restore the required files separately from the archive.

Common examples:

Tar-CF archive.tar Foo bar # create archive file archive.tar from file Foo bar.

The tar-tvf archive.tar file details all the files in archive.tar.

Tar-XF archive.tarveshows all files in archive.tar.

Master operation mode:

-A, -- catenate, -- concatenate: append the tar file to the archive.

-C, -- create creates a new archive

-D, -- diff, -- compare to identify the differences between the archive and the current file

-- Delete: delete an archive.

-R, -- append: append the file to the end of the archive.

-T, -- list: List archived content

-U, -- Update: only append Files updated compared to files in the archive

-X, -- Extract, -- get to Extract files from the archive

Device selection and switching:

-F, -- file = archive use an archive file or an archive Device

Compression options:

-A, -- auto-compress uses the archive suffix to determine the compression program

-J, -- Bzip2 uses Bzip2 to filter Archives

-J, -- xz filter and archive through xz

-Z, -- gzip, -- gunzip, -- ungzip filter and archive through Gzip

Local file selection:

-- Add-file = file: add the specified file to the archive.

-C, -- directory = dir changed to directory dir

-V, -- verbose detailed list of processed files

-- Warning = keyword Warning Control:

Example (the following examples are run as root users ):
Example 1: package all the files in the/Home Directory into/usr/backup/home.tar.
# Tar-CVF/usr/backup/home.tar/home <-- only package, not compressed
# Tar-zcvf/usr/backup/home.tar.gz/home <-- compressed with Gzip
# Tar-jcvf/usr/backup/home.tar.bz2/home <-- Compress With Bzip2
Note: The file name after parameter F is obtained by yourself. It is often identified by. Tar.

Example 2: Check the files in the/usr/backup/home.tar.gz File above?
# Tar-ztvf/usr/backup/home.tar.gz
Because Gzip is used for compression, you have to add the Z parameter when you want to view the files in the TAR file!

Example 3: Decompress the/usr/backup/home.tar.gz file under/usr/local/src.
Method 1:
# Cd/usr/local/src
# Tar-zxvf/usr/backup/home.tar.gz
Method 2:
# Tar-zxvf/usr/backup/home.tar.gz-C/usr/local/src/

Example 4: Under/tmp, I only want to unbind the home/root in/usr/backup/home.tar.gz.
# Cd/tmp
# Tar-zxvf/usr/backup/home.tar.gz home/root

Example 5: Back up all files in/home/and save the permission!
# Tar-zxvpf/usr/backup/home.tar.gz/home
Note: This-P attribute is very important, especially when you want to retain the attributes of the original file!
The file name needs to be received immediately after F! Do not add parameters! In the preceding example, tar-zxvfp/usr/backup/home.tar.gz is incorrect.

Example 6: In/home, a new file is backed up only after 2007/06/01.
# Tar-n "2007/06/01"-zcvf home.tar.gz/home

Example 7: I want to back up/home,/etc, but not/home/ABC
# Tar -- exclude/home/ABC-zcvf myfile.tar.gz/home/*/etc

Example 8: unpack/home/and unbind it under/tmp without generating a file!
# Cd/tmp
# Tar-CVF-/home | tar-xvf-
Note that the output file is changed to-, and the input file is changed -.

Example 9: Create a new user BCD After packaging/home, and package it into/usr/backup/home.tar.gz.
# Tar-zcvrf/usr/backup/home.tar.gz/home/BCD

 

References: http://zzjnet.blog.51cto.com/323001/318766

GNU tar -- Help

 

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.