Linux command (IN): Tar command-archive tool

Source: Internet
Author: User
Tags bz2

Tar command

Function description

TAR is an acronym for Tape archive, a frequently used archive tool under Linux, often seeing files with the file names ending in. tar and tgz, which are files that are archived with the normal TAR commands and files that are archived with gzip. A tar archive can be composed of many separate files, one or more directory hierarchies, or a mixture of both. Use the following:

tar [main option + Secondary options] file or directory

Common parameters

Options Description
-C New file
-R List the contents of an archive file
-T List the files already archived in the archive file
-X Restore a file from a packaged archive file
-U Update the archive and replace the original file with the new file
-Z Call the gzip command to compress/unzip files during the packaging process
-j Call the BZIP2 command to compress/unzip files during the packaging process
-j Call the XZ command to compress/unzip files during packaging
-W When restoring a file, set the modification time of all files to the current time
-Z Filter files with the Compress command
-F The "-F" option is immediately followed by the file's storage device, which defaults to the disk, the file file name needs to be specified, and if it is a tape, simply specify the tape device name. Note that you cannot follow any other options after the "-F" option, which means "-F" must be the last option of the tar command
-V Specifies that the name of each archive file is displayed during the creation of the archive file
-P Keep the properties of the file unchanged during file archiving
-N "Yyyy/mm/dd" Files after the specified date are not packaged in the archive file
--exclude file During the packaging process, the specified file file is not packaged


Example

     using CF compression , package the test folder in the current directory into a Test.tar, in order to facilitate the demonstration, in advance to copy the app files to test a copy

[[email protected] app]# tar-cf test.tar test/

[[email protected] app]# ll-h

Total usage 432K

-rw-r--r--. 1 root root  181 November 17:34 99.sh

-rw-------. 1 root root  12k November 14:08 messages

-rw-r--r--. 1 root root 1.2K November 15:17 messages2.gz

-rw-r--r--. 1 root root 1.2K November 14:36 messages.gz

-rw-r--r--. 1 root root 141K November 10:17 shell.txt

-rw-r--r--. 1 root root  48k November 10:17 shell.txt.bz2

Drwxr-xr-x. 2 root root 4.0K November 17:07 test

-rw-r--r--. 1 root root 210K November 17:21 Test.tar


    use < Strong style= "padding:0px;margin:0px;" >XF decompression , Unzip the file to the specified directory using the-C

[[email protected] app]# mkdir test1                 &NB Sp     #创建目标目录test1

[[email protected] app]# pwd

/root/app

[[email]  protected] app]# tar xf test.tar-c./test1/        #解压到test1下

[[email protected] app]# ls./test1/test/         & nbsp         #验证查看

99.sh  messages  messages2.gz  messages.gz  shell.txt  shell.txt.bz2

use Bzcat to find out what 's on your file

[Email protected] app]# bzcat shell.txt.bz2 | more


This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1875880

Linux command (IN): Tar command-archive tool

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.