Tar & gzip command

Source: Internet
Author: User
Tags gz file

TheTar
(Tape archive) command bundles a bunch of files together and creates an archive (commonly calledTar file
Or
Tarball
) On a tape, disk drive, or floppy disk. The original files are not deleted after being copied to the TAR file.


Usage:
List: tar-TF <archive-FILENAME>
Extract: tar-XF <archive-FILENAME>
Create: tar-cf <archive-FILENAME> [filenames...]

 

To create an archive usingTar
, Use a command like this, which bundles all the files in the current directory that end. Doc
IntoAlldocs.tar
File:

Tar C
VF alldocs.tar *. Doc





Here's a second example, which creates a tar file namedPanda.tar
Containing all the files fromPanda
Directory (and
Any of its subdirectories ):

Tar CVF panda.tar panda/




In these examples,C
,V
, AndF
Flags mean create a new archive, be verbose (list files being archived), and write the archive to
File. You can also create tar files on tape drives or floppy disks, like this:

Tar cvfm/dev/fd0 panda

Archive the files in the panda directory to floppy disk (s ).
Tar CVF/dev/rmt0 panda

Archive the files in the panda directory to the tape drive.

The/Dev/fd0
Entry is Linux-ese for "Floppy Drive zero" (your a drive under DOS), and/Dev/rmt0
Means "removable media
Tape Zero, "or your primary tape drive.M
Flag means use multiple floppy disks -- when one disk is full,Tar
Prompts you
Insert another.

To automatically compress the tar file as it is being created, addZ
Flag, like this:

Tar cvz
F alldocs.tar.gz *. Doc



In this example, I added. GZ
Suffix to the archive file name, becauseZ
Flag tellsTar
To use the same compression as
Gzip
Command.

 

To list the contents of a tar file, useT
(Type) flag in a command, like this:

Tar t
VF alldocs.tar


List all files inAlldocs.tar
.


To extract the contents of a tar file, useX
(Extract) flag in a command, like this:

Tar x
VF panda.tar


Extract files fromPanda.tar
.

This will copy all the files fromPanda.tar
File
Into the current directory. When a tar file is created, it can bundle
Up all
Files in a directory, as well as any subdirectories and the files in
Them. So when you're extracting a tar file, keep in mind that you
Might end up with some new subdirectories in the current directory.

We 've used several different flags in the sampleTar
Commands so far. Here's a list of the most common flags:

C
Create a new archive.
T
List the contents of an archive.
X
Extract the contents of an archive.
F
The archive file name is given on the command line (required whenever the tar output is going to a file)
M
The archive can span multiple floppies.
V
Print verbose output (list file names as they are processed ).
U
Add files to the archive if they are newer than the copy in the TAR file.
Z
Compress or decompress files automatically.

 

Gzip:

There are two obvious advantages to reduce the file size. One is to reduce the storage space, and the other is to reduce the transmission time when the file is transmitted over the network. Gzip is a frequently used command in Linux to compress and decompress files, which is convenient and easy to use.

Syntax: gzip [Option] compressed (decompressed) file name
  

The options of this command are as follows:
  

-C writes the output to the standard output and keeps the original file.
  

-D. decompress the compressed file.
  

-L the following fields are displayed for each compressed file:
  

Size of the compressed file; size of the uncompressed file; compression ratio; Name of the uncompressed File
-R recursively searches for the specified directory and compresses all the files or decompress the files.
-T test to check whether the compressed file is complete.
  

-V displays the file name and compression ratio for each compressed and decompressed file.
  

-Num: Use the specified numeric num to adjust the compression speed,

-1 or -- fast indicates the fastest compression method (low compression ratio ),
-9 or -- best indicates the slowest compression method (high compression ratio ). The default value is 6.
  

 

Command instance:
Gzip *
% Compress each file in the current directory into A. GZ file.
  

Gzip-DV *
% Decompress each compressed file in the current directory and list detailed information.
  

Gzip-L *
% Detailed information of each compressed file in Example 1 is displayed without decompression.
  

Gzip usr.tar
% Decompress the tar backup file usr.tar. the extension name of the compressed file is .tar.gz.

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.