Linux tar command parameters and usage details--linux Package backup command

Source: Internet
Author: User
Tags gz file

Linux tar command parameters and usage details--linux Package backup command tarCommand

GNU version of the Tar-tar file management program. The meanings are described below
tar [-cxtzjvfppn] files and directories ....
Common parameters:
-C: Establish a Compress the parameters directive of the file (the meaning of Create);
-X : Unlock the parameter instructions for a compressed file!
-T: View Tarfile   files inside! The
special note that in the release of the parameter, c/x/t can only exist one! Cannot exist at the same time!
because it is not possible to compress with decompression .
-Z: Is there a property for Ggzip   compression?
-j: Do you have properties for  -V: Files are displayed during compression! This is commonly used, but is not recommended for use in the background execution process!
-F: Use the file name, please note, after F to immediately answer the file name Oh! Don't add any more arguments!
For example, using "TAR-ZCVFP tfile sfile" is the wrong way to write a
"TAR-ZCVPF tfile sfile".
-P: Use the original file's original property (the property will not change according to the consumer)
-P: You can use absolute path to compress!
-N: Newer than the next date (Yyyy/mm/ex clude file: Do not package file in the process of compression!  

Describe
The TAR program is used to store or expand a tar archive file. Archive files can be placed on disk or saved as normal files. Tar is a parameter, the optional parameter is a, C, D, r, T, u, x, you must first specify at least one parameter for tar when you use tar, and then you must specify the file or directory to process. If you specify a directory, all subdirectories under that directory are added to the archive.
Application Examples:

1) Expand abc.tar.gz Use command: Tar xvzf abc.tar.gz expand abc.tar Use command: Tar xvf abc.tar

2) Save the Man directory and its subdirectories under the current directory as archived Man.tar tar CF Man.tar./man
Detailed parameter Description:
At least one of the following parameters must be run when you run tar

-A,--catenate,--coNCatenate
Merging an archive with an existing archive
-C,--create
Create a new archive
-D,--diff,--compare
Compare the differences between the archive and the current file
--delete
Remove from archive
-R,--append
Append to end of archive
-T,--list
Lists the directories of files in the archive
-U,--update
Attach only newer files to the archive
-X,--exTRAct,--get
To expand a file from an archive


Other parameters

--aTime-preserve
Do not change the access time of the dump file

-B,--block-size N
Specify a block size of Nx512 bytes (default n=20)

-B,--read-full-blocks
When reading the reorganization block (???!!! )

-C,--directory DIR

Go to the specified directory

--checkpoint
Show directory name when reading archive

-F,--file [hostname:]f
Specify an archive or device (default is/dev/rmt0)

--force-local
Force local archive, even if a clone exists

-F,--info-script F--new-volume-script F
Use script F (implied-m) at the end of each disk

-G,--incremental
Build a backup of the old GNU format

-G,--listed-incremental F
Create a backup of the new GNU format

-H,--dereference
Does not dump dynamic links, dumps the files that the dynamic links point to.

-I.,--ignore-zeros
Ignores 0-byte blocks in the archive (usually means end of file)

--ignore-failed-read
Make 0 mark in non-readable file before exiting???

-K,--keep-old-files
Save an existing file, and do not overwrite it when expanded from the archive

-K,--starting-file F
Start with the archive file F

-L,--one-file-system
Create an archive in the local file system

-L,--tape-length N
Pause after writing n*1024, wait for disk replacement

-M,--modification-time
When recovering files from an archive, do not use the new Time label

-M,--multi-volume
Create a multi-volume archive to store on several disks

-N,--after-date date,--newer date
Only files with newer time are stored

-O,--old-archive,--portability
Archive in V7 format, without ANSI format

-O,--to-stdout
To expand a file to standard output

-P,--same-permissions,--preserve-permissions
Expand All Protection information

-P,--absolute-paths
Do not remove the '/' from the file name

--preserve
Like-p-S
Similar to-p-s

-R,--record-number
Displays the number of records in the archive while displaying information

--remove-files
Delete a source file after you create an archive

-S,--same-order,--preserve-order
???
--same-owner
Expand to make all files belong to the same owner

-S,--sparse
Efficient processing

-T,--files-from F
Get the file name you want to expand or create from your files

--null
Read null-terminated file name, so-C fails

--totals
Displays the total number of bytes written with the--create parameter

-V,--verbose
Detailed display of processed files

-V,--label NAME
Assign a volume label to an archive

--version
Displays the version number of the TAR program

-W,--interactive,--confirmation
Each operation requires confirmation

-W,--verify
Verify after writing to archive

--exclude FILE
Do not include the specified file

-X,--exclude-from FILE
Reads a list of files that you do not want to include from the specified file

-Y,--bzip2,--bunzip2
Compress or decompress an archive with bzip2

-Z,--compress,--uncompress
Compress or decompress an archive with compress

-Z,--gzip,--ungzip
Compress or decompress an archive with gzip

--use-compress-program PROG
Compress or decompress the archive with PROG (PROG need to accept the-D parameter)

--block-compress
Archive by Block records for easy disk storage

-[0-7][LMH]
Specify drive and density [high school low]

--------------------------

Usage examples:

Package: TAR-CF Soft.tar Soft

Unpacking: tar-xf Soft.tar Soft

Compressed directory

Package compression: Tar czvf usr.tar.gz/home

Decompression: Tar xzvf usr.tar.gz

Compress files (for directory invalidation)

Compression: Zip good.zip good1 good2

Decompression: Unzip Good.zip

Example one: Package all the files in the/etc directory into/tmp/etc.tar
[email protected] ~]#
tar-cvf/tmp/etc.tar/etc<== only packaged, not compressed!
[[email protected] ~]# tar-zcvf/tmp/etc.tar.gz/etc<== packaged, compressed with gzip
[[email protected] ~]# tar-jcvf/tmp/etc.tar.bz2/etc<== packaged, bzip2 compressed
# Note that the file name after parameter f is taken by yourself, and we are accustomed to using. Tar as a recognition.
# if the z parameter is added, the. tar.gz or. tgz represent the gzip compressed tar file ~
# If you add the J parameter, use. tar.bz2 as the file name.
# When the above instruction is executed, a warning message is displayed:
# "tar:removing leading"/"from member names" that is a special setting for absolute paths.

Example two: Check out what files are in the above/tmp/etc.tar.gz file?
[Email protected] ~]# tar-ztvf/tmp/etc.tar.gz
# because we use gzip compression, so to check the file in the tar file,
# you have to add Z to this parameter! It's important!

Example three: Extracting the/tmp/etc.tar.gz file under/USR/LOCAL/SRC
[Email protected] ~]# CD /usr/local/src
[Email protected] src]# tar-zxvf/tmp/etc.tar.gz
# in the case of presets, we can unzip the file anywhere! In the case of this example,
# I'm going to transform my working directory under/USR/LOCAL/SRC and untie/tmp/etc.tar.gz,
# then the unpacked catalogue will be in/USR/LOCAL/SRC/ETC! Also, if you enter/USR/LOCAL/SRC/ETC
# you will find that the file attributes in this directory may be different from the/etc/.

Example four: under/tmp, I just want to/tmp/etc.tar.gz the etc/in thepasswd .
[Email protected] ~]# cd/tmp
[Email protected] tmp]# tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can check the file name in the Tarfile through TAR-ZTVF, if only one file,
# can be released in this way! Notice that! The root directory within the etc.tar.gz/is taken away!

Example five: Back up all the files in the/etc/and save their permissions!
[Email protected] ~]# tar-zxvpf/tmp/etc.tar.gz/etc
# The properties of this-p are important, especially if you want to keep the properties of the original file!

Example six: In/home, more than 2005/06/01 new files are backed up
[Email protected] ~]# tar-n "2005/06/01"-ZCVF home.tar.gz/home

Linux tar command parameters and usage details--linux Package backup command

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.