linux-(Tar,gzip)

Source: Internet
Author: User
Tags gz file rar uncompress

Tar command

The first thing to understand is two concepts: packaging and compression. Packaging refers to a large number of files or directories into a total file, compression is a large file through some compression algorithm into a small file.

Why should we differentiate between these two concepts? This is due to the many compression programs in Linux that can only be compressed for one file , so that when you want to compress a lot of files, you have to first make a package (Tar command) of the whole bunch of files, and then compress the program (gzip bzip2 command). The tar itself does not have compression capabilities. It is implemented by invoking the compression function

1. Command format:

tar [Required parameters] [select parameters] [file]

2. Command parameters:

The necessary parameters are as follows:

-A add compressed file to existing compression

-B Set Chunk size

-C Create a new compressed file

-D Record File differences

-R Add a file to a file that has been compressed

-u add changed and existing files to a compressed file that already exists

-X extracting files from compressed files

-T displays the contents of the compressed file

-Z Support gzip unzip files

-j Support bzip2 Extract files

-Z Support Compress unzip files

-V Show Operation procedure

-L File System boundary settings

-K Keep the original file without overwriting

-m reserved files are not overwritten

-W confirm the correctness of the compressed file

The optional parameters are as follows:

-B Set Number of blocks

-c switch to the specified directory

-f Specifies the compressed file

--HELP Display Help information

--version displaying version information

3. Common decompression/Compression commands

. tar
Unpacking: Tar xvf Filename.tar
Package: Tar cvf filename.tar DirName
(Note: Tar is packaged, not compressed!) )

. gz
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
Compression: gzip FileName

. tar.gz and. tgz
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName

. bz2
Decompression 1:bzip2-d filename.bz2
Decompression 2:BUNZIP2 filename.bz2
Compression: Bzip2-z FileName

. tar.bz2
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName

. BZ
Decompression 1:bzip2-d filename.bz
Decompression 2:BUNZIP2 filename.bz
Compression: Unknown

. tar.bz
Decompression: Tar jxvf FileName.tar.bz
Compression: Unknown
. Z
Decompression: uncompress filename.z
Compression: Compress FileName

. Tar. Z
Decompression: Tar zxvf filename.tar.z
Compression: Tar zcvf filename.tar.z DirName

. zip
Decompression: Unzip Filename.zip
Compression: Zip Filename.zip DirName
. rar
Decompression: rar x Filename.rar
Compression: rar a Filename.rar DirName

4. Working with instances

Package all files into a tar package

Command:

TAR-CVF Log.tar Log2012.log Package only, do not compress!

TAR-ZCVF log.tar.gz log2012.log After packing, compress with gzip

TAR-JCVF log.tar.bz2 Log2012.log is packaged to bzip2 compression

The file name after the parameter F is taken by itself, and is used in the habit of. Tar as identification. If the z parameter is added, a. tar.gz or. tgz is used to represent the gzip compressed tar package, or the. tar.bz2 as the TAR package name if the J parameter is added.

Check which files are in the tar package above

Command: TAR-ZTVF log.tar.gz

Extract only some of the files in the/tar

Command: TAR-ZCVF log30.tar.gz log2012.log Log2013.log

TAR-ZTVF can be used to check the file name in the TAR package, if only a single file, you can use this way to extract some files!

Files are backed up and their permissions are saved

Command: TAR-ZCVPF log31.tar.gz log2014.log log2015.log log2016.log

Description: This-P property is important, especially if you want to preserve the properties of the original file

In a folder, a new file is backed up than a date

Command: Tar-n "2012/11/13"-ZCVF log17.tar.gz test

Backup folder content is excluded from some files

Command: Tar --exclude scf/service-zcvf scf.tar.gz scf/*

gzip Command 1. Command format:

gzip [parameters] [file or directory]

2. Command function:

Gzip not only compresses large, less-used files to conserve disk space, but also, together with the TAR commands, forms the most popular compressed file format in the Linux operating system. According to statistics, the gzip command has a 60%~70% compression rate for text files. Gzip is a widely used compression program, after which the file is compressed, and its name is followed by a ". gz" extension.

3. Command parameters:

-A or--ASCII use ASCII text mode.

-C or--stdout or--to-stdout the compressed file output to the standard output device, not to change the original file.

-D or--decompress or----uncompress unpack the compressed file.

-F or--force forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection.

-H or--help online Help.

-L or--list lists information about the compressed file.

-L or--license display version and copyright information.

The original file name and time stamp are not saved when the file is compressed by-N or--no-name.

-N or--name compress the file, save the original file name and time stamp.

-Q or--quiet does not display a warning message.

-R or--recursive recursively handles all files and subdirectories under the specified directory.

-s< compress the tail string > or----suffix< compress the tail string > change the compressed Word tail string.

-T or--test tests whether the compressed file is correct.

-V or--verbose shows the instruction execution process.

-V or--version displays version information.

-num adjusts the speed of compression with the specified number num,-1 or--fast represents the fastest compression method (low compression ratio), 9 or--best represents the slowest compression method (high compression ratio). The system default value is 6.

4. Usage examples:

Compress each file in the Test6 directory into a. gz file

Command: gzip *

Unzip each compressed file and list detailed information

Command: GZIP-DV *

[Root@localhostTEST6]#llTotal604---xr--r--1Root Mail302108  One- -  ,: theLinklog.Log---xr--r--1Mail users302108  One- -  ,: thelog2012.Log[Root@localhostTEST6]#gzip *[Root@localhostTEST6]#llTotal ----xr--r--1Root Mail1341  One- -  ,: theLinklog.Log.GZ---xr--r--1Mail users1341  One- -  ,: thelog2012.Log.GZ

[Root@localhostTEST6]#llTotal ----xr--r--1Root Mail1341 One- - ,: theLinklog.Log.GZ---xr--r--1Mail users1341 One- - ,: thelog2012.Log.Gz[root@localhostTEST6]#GZIP-DV *Linklog.Log. GZ:99.6%--replaced with Linklog.Loglog2012.Log. GZ:99.6%--replaced with log2012.Log[Root@localhostTEST6]#llTotal604---xr--r--1Root Mail302108 One- - ,: theLinklog.Log---xr--r--1Mail users302108 One- - ,: thelog2012.Log[Root@localhostTEST6]#

Detailed display of each compressed file information, and do not understand the pressure

Command: Gzip-l *

[Root@localhostTEST6]#Gzip-l *compressed uncompressed ratio uncompressed_name1341              302108  99.6% Linklog.Log               1341              302108  99.6% log2012.Log                  -                   A  47.5% log2013.Log               2880              604277  99.5% (totals)

Compresses a tar backup file, at which time the compressed file has the extension. tar.gz

Command: Gzip-r Log.tar

Recursive compression directory

Command: GZIP-RV test6

[Root@localhostTEST6]#llTotal604---xr--r--1Root Mail302108  One- -  ,: theLinklog.Log---xr--r--1Mail users302108  One- -  ,: thelog2012.Log[Root@localhostTEST6]#CD..[Root@localhostTest#GZIP-RV Test6Test6/linklog.Log:99.6%--replaced with Test6/linklog.Log.Gztest6/log2012.Log:99.6%--replaced with test6/log2012.Log.Gz[root@localhostTest#CD Test6[Root@localhostTEST6]#llTotal ----xr--r--1Root Mail1341  One- -  ,: theLinklog.Log.GZ---xr--r--1Mail users1341  One- -  ,: thelog2012.Log. gz

linux-(Tar,gzip)

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.