Linux tar packaging command

Source: Internet
Author: User
Tags unpack uncompress

Example 1: package all the files in the/etc directory into/tmp/etc.tar
[Root @ linux ~] # Tar-cvf/tmp/etc.tar/etc <= package only, do not compress!
[Root @ linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with gzip
[Root @ linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with bzip2
# 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.

Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ linux ~] # Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the tar file,
# Add the z parameter! This is important!

Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ linux ~] # Cd/usr/local/src
[Root @ linux src] # tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The file attributes in this directory may be different from those in/etc!

Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. If you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!

Example 5: Back up all the files in/etc/and save their permissions!
[Root @ linux ~] # Tar-zxvpf/tmp/etc.tar.gz/etc
# This-p attribute is very important, especially when you want to keep the attributes of the original file!

Example 6: only new files in/home are backed up.
[Root @ linux ~] # Tar-N '2014/1/01 '-zcvf home.tar.gz/home

Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ linux ~] # Tar-exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc

Example 8: package/etc/and unpack it under/tmp without generating a file!
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-cvf-/etc | tar-xvf-
# This action is a bit like cp-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!
# This part will be explained again when we mention this command in Bash shell!

. Tar
Unpack: tar xvf FileName.tar
Package: tar cvf FileName.tar DirName
(Note: tar is packed, not compressed !)
---------------
. Gz
Decompress 1: gunzip FileName.gz
Decompress 2: gzip-d FileName.gz
Compression: gzip FileName
.Tar.gz and. tgz
Decompress: tar zxvf FileName.tar.gz
Compression: tar zcvf FileName.tar.gz DirName
---------------
. Bz2
Decompress 1: bzip2-d FileName.bz2
Decompress 2: bunzip2 FileName.bz2
Compression: bzip2-z FileName
.Tar.bz2
Decompress: tar jxvf FileName.tar.bz2 or tar-bzip xvf FileName.tar.bz2
Compression: tar jcvf FileName.tar.bz2 DirName
---------------
. Bz
Extract 1: bzip2-d FileName. bz
Decompress 2: bunzip2 FileName. bz
Compression: Unknown
. Tar. bz
Decompress: tar jxvf FileName.tar. bz
Compression: Unknown
---------------
. Z
Decompress: uncompress FileName. Z
Compression: compress FileName
. Tar. Z
Decompress: tar Zxvf FileName.tar. Z
Compression: tar Zcvf FileName.tar. Z DirName
---------------
. Zip
Decompress: unzip FileName.zip
Compression: zip FileName.zip DirName
Use the-r parameter to compress a directory and use-r recursion. Example: $ zip-r FileName.zip DirName
---------------
. Rar
Decompress: rar x FileName.rar
Compression: rar a FileName.rar DirName
Rar Please download to: http://www.rarsoft.com/download.htm!
After decompression, copy rar_static to the/usr/bin directory (Other Directories specified by the $ PATH environment variable can also be used ):

From: webshell blog


 

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.