Let's take a look at an example:
1.compress all. txt files under the current directory and archive them to the this.tar.gz file. We can use
Tar zcvf this.tar.gz./*. txt
2.decompress the files in this.tar.gz under the current directory to the current directory.
Tar xzvf this.tar.gz ./
The following describes several important parameters:
(1) packaging some parameters
Tar [-] A -- catenate -- concatenate | C -- create | D -- diff -- Compare | -- delete | r -- append | T -- list | -- Test-label | u -- Update | X
-- Extract -- get [Options] [pathname...]
Main Operation Mode:
I. Create tar
-C, -- create
Create a new archive
1 # After tar-CF target.tar file1 file2... 2 is created, you can use the-a-r parameter to add the 3 -- delete parameter to delete it.
Ii. add or delete
-A, -- catenate, -- concatenate
Append tar files to an archive
-R, -- append
Append files to the end of an archive
-- Delete
Delete from the archive (not on Mag tapes !)
1 # tar-AF target.tar source1.tar source2.tar... add other packaging files to a packaging file 2 # tar-RF target.tar file1 file2... add other files to a packaging File
3 # tar-F target.tar -- delete file1 file2... delete a file from a package file
Iii. View
-D, -- diff, -- compare
Find differences between archive and File System
-T, -- list is a useful option.
List the contents of an archive
-U, -- Update is also a useful option.
Only append files newer than copy in archive
1 # tar-TF target.tar view the content in the package file 2 # tar-DF target.tar file 3 # tar-UF target.tar file1 file2... update the content in the package file
Iv. Unlock
Since packaging is inevitable
-X, -- Extract, -- get
Extract files from an archive
1 #tar -xf target.tar
(2) Compression Parameters
Specify the compression algorithm parameters
-J, -- Bzip2
-Z, -- gzip, -- gunzip -- ungzip
-Z, -- compress, -- uncompress
(3) Others
-V, -- verbose
Verbosely list files processed
This parameter is equivalent to displaying the process to you.
(4) common combinations
Some combinations are generated for the following format:
1 # tar-zcvf target.tar.gz/DIR package, compress it with gzip 2 # tar-jcvf target.tar.gz/Dir, compress it with Bzip2 3 4, replace the-C parameter with the-x parameter to decompress 5 6 # tar-zcvf target.tar.gz/DIR gzip unzip 7 # tar-jcvf target.tar.gz/DIR Bzip2 unzip
[[Email protected] ~] # Tar-CVF/tmp/etc.tar/etc<= Package only, not compressed!
[[Email protected] ~] #Tar-zcvf/tmp/etc.tar.gz/etc<= Compressed with gzip After packaging
[[Email protected] ~] #Tar-jcvf/tmp/etc.tar.bz2/etc<= Compressed with Bzip2 After packaging
# Note that the file name after parameter F is obtained by ourselves. We use. tar for identification.
# If the Z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the J parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:
# "Tar: removing leading '/' from Member names" is a special setting for absolute paths.
Tar -- package compressed files