TAR
Command name
The GNU version of the tar-tar file management program. The following sections describe their meanings one by one.
Overview
Tar [-] A -- catenate -- concatenate | c -- create | d -- diff -- compare | r -- append | t -- list | u -- update | x-extract -- get [-- atime -preserve] [-B, -- block-size N] [-B, -- read-full-blocks] [-C, -- directory DIR] [-- checkpoint]
[-F, -- file [HOSTNAME:] F] [-- force-local]
[-F, -- info-script F -- new-volume-script F] [-G, -- incremental] [-g, -- listed-incremental F] [-h, -- dereference] [-I, -- ignore-zeros] [-I, -- bzip] [-- ignore-failed-read] [-k, -- keep-old-files] [-K, -- starting-file F] [-l, -- one-file-system] [-L, -- tape-length N] [-m, -- modification-time] [-M, -- multi-volume] [-N, -- after-date DATE, -- newer DATE] [-o, -- old-archive, -- portability] [-O, -- to-stdout] [-p, -- same-permissions, -- preserve-permissions] [-P, -- absolute-paths] [-- preserve]
[-R, -- record-number] [-- remove-files] [-s, -- same-order, -- preserve-order] [-- same-owner] [-S, -- sparse] [-T, -- files-from F] [-- null]
[-- Totals]
[-V, -- verbose] [-V, -- label NAME] [-- version]
[-W, -- interactive, -- confirmation] [-W, -- verify]
[-- Exclude FILE] [-X, -- exclude-from FILE] [-Z, -- compress, -- uncompress] [-z, -- gzip, -- ungzip]
[-- Use-compress-program PROG] [-- block-compress] [-[0-7] [lmh]
Filename1 [filename2,... filenameN]
Directory1 [directory2,... directoryN]
Description
The tar program is used to store or expand tar archive files. Archive files can be stored on disks or as common files. Tar requires parameters. Optional parameters include A, c, d, r, t, u, and x. You must specify at least one parameter for tar before using tar, you must specify the file or directory to process. If a directory is specified, all subdirectories under the directory will be added to the archive.
Example:
1) Expand abc.tar.gz run the command tar xvzf abc.tar.gz expand abc.tar run the command tar xvf abc.tar
2) Save the man directory and Its subdirectories in the current directory as an archive man.tar cf man.tar./man
Parameter description
To run tar, you must have at least one of the following parameters.
-A, -- catenate, -- concatenate
Merge an archive with an existing archive
-C, -- create
Create a new archive
-D, -- diff, -- compare
Compare the differences between an archive and the current file
-- Delete
Delete from archive
-R, -- append
Append to end of Archive
-T, -- list
List directories of files in an archive
-U, -- update
Only append newer files to the Archive
-X, -- extract, -- get
Expand an object from an archive
Other parameters
-- Atime-preserve
Do not change the access time of the dump file
-B, -- block-size N
Specify the block size as Nx512 bytes (N = 20)
-B, -- read-full-blocks
Reorganize the block when reading (???!!!)
-C, -- directory DIR
Go to the specified directory
-- Checkpoint
Displays the directory name when reading the archive.
-F, -- file [HOSTNAME:] F
Specify an archive or device (/dev/rmt0 by default)
-- Force-local
Use a local archive forcibly, even if a clone exists
-F, -- info-script F -- new-volume-script F
Use the script F (implicit-M) at the end of each disk)
-G, -- incremental
Create a backup in the old GNU format
-G, -- listed-incremental F
Create a new GNU backup
-H, -- dereference
Do not dump the dynamic link. Dump the file that the dynamic link points.
-I, -- ignore-zeros
Ignore the 0-byte block in the archive (usually means the end of the file)
-- Ignore-failed-read
Mark 0 in the unreadable file before exiting ???
-K, -- keep-old-files
Save existing files; Do not overwrite them when expanding from the archive
-K, -- starting-file F
Starting from archive file F
-L, -- one-file-system
Create an archive in the local file system
-L, -- tape-length N
Pause after writing N * 1024 bytes and wait for disk replacement
-M, -- modification-time
When a file is recovered from an archive, no new time tag is used.
-M, -- multi-volume
Create a multi-volume archive for storage on several disks
-N, -- after-date DATE, -- newer DATE
Only store new files
-O, -- old-archive, -- portability
Archive in V7 format without ANSI format
-O, -- to-stdout
Expand the file to standard output
-P, -- same-permissions, -- preserve-permissions
Expand All Protection Information
-P, -- absolute-paths
Do not remove '/' from the file name '/'
-- Preserve
Like-p-s
Similar to-p-s
-R, -- record-number
Displays the number of records in the archive at the same time.
-- Remove-files
Delete source files after creating 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
Obtain the name of the file to be expanded or created from the file.
-- Null
Read an empty ending file name to invalidate-C.
-- Totals
Displays the total number of bytes written with the -- create parameter.
-V, -- verbose
Detailed display of processed files
-V, -- label NAME
Specify the volume label for the archive
-- Version
Displays the version number of the tar program.
-W, -- interactive, -- confirmation
Each operation requires confirmation.
-W, -- verify
Verify after writing to the Archive
-- Exclude FILE
Does not include the specified file
-X, -- exclude-from FILE
Reads the list of files not included from the specified file
-Y, -- bzip2, -- bunzip2
Use bzip2 to compress or decompress the archive
-Z, -- compress, -- uncompress
Compress archive compression or decompression
-Z, -- gzip, -- ungzip
Use gzip to compress or decompress the archive
-- Use-compress-program PROG
Use PROG to compress or decompress the archive (the PROG must accept the-d parameter)
-- Block-compress
Archive records by block for ease of disk storage
-[0-7] [lmh]
Specify the drive and density [High and Low]
--------------------------
Package: tar-cf soft.tar soft
Unpack: tar-xf soft.tar soft
Compressed directory
Compressed: tar czvf usr.tar.gz/home
Decompress: tar xzvf usr.tar.gz
Compressed file (invalid directory)
Compression: zip good.zip good1 good2
Decompress: unzip good.zip
From: http://blog.csdn.net/yinchongyi/archive/2006/11/02/1362350.aspx
Tar, gzip, and unzip
Tar command
Tar can create files and directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now, you can create files, such as floppy disks, on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission.
Tar on Linux is of the GNU version.
Syntax: tar [primary option + secondary option] file or directory
When you use this command, the main option is required, and it tells tar what to do. The auxiliary option is used for assistance and can be used.
Main options:
C. Create a new archive file. Select this option if you want to back up a directory or some files.
R: append the file to the end of the file.
For example, if the user has prepared a backup file and finds another directory or file has forgotten to be backed up,
You can use this option to append the directory or file you forget to the backup file.
T list the file content and check which files have been backed up.
U updates the file. That is to say, replace the original backup file with the new file. If the file to be updated cannot be found in the backup file, append it to the end of the backup file.
X release a file from the file.
Auxiliary options:
B. This option is set for the tape drive. It is followed by a number to describe the block size. The default value is 20 (20*512 bytes ).
F. This option is usually required when you use an archive file or device.
K. Save the existing files. For example, if we restore a file, the same file will not be overwritten during restoration.
M sets the modification time of all files to the present when restoring files.
M creates a multi-volume archive file to store it on several disks.
V detailed report on the file information processed by tar. If this option is not available, tar does not report file information.
W each step requires confirmation.
Z uses gzip to compress/decompress the file. With this option, the file can be compressed. However, you must use this option to decompress the file during restoration.
Analysis of compressed files in Linux
For those who are new to Linux, they will surely get dizzy with a bunch of various file names in Linux.
For example, we know that there are only two common types of compressed files in Windows: zip and. rap.
It can be different from Linux. There are many compressed file names such as .gz).tar.gz?tgz=bz22.16.z#.tar,
In Windows, .ziphe .rarcan also be used in linux, and too few people use .zipand .rar in linux.
This article will summarize these common compressed files. I hope you will not be confused when you encounter these files.
At the end of lifecycle. After the tar package is generated, you can use other programs to compress it. So let's first talk about the basic usage of the tar command:
There are many options for the tar command (which can be viewed using man tar), but there are several commonly used options. The following is an example:
# Tar-cf all.tar *. jpg
This command is to pack all. jpg files into a package named all.tar. -C indicates that a new package is generated.-f specifies the package file name.
# Tar-rf all.tar *. gif
This command adds all .gif files to the package of all.tar. -R indicates adding files.
# Tar-uf all.tar logo.gif
This command is used to update the logo.gif file in tarbao all.tar.-u indicates that the file is updated.
# Tar-tf all.tar
This command is used to list all files in the all.tar package.-t is used to list objects.
# Tar-xf all.tar
This command is used to extract all the files in the all.tar package.
The above is the most basic usage of tar.
To help you compress or decompress files while packing and unpackage, tar provides a special feature. This means that tar can call other compression programs, such as gzip and bzip2, while packaging or unpacking.
1) tar calls gzip
Gzipis a program developed by gnuorganization. The file ending with .gz is the result of gzip compression. The decompress program relative to gzip is gunzip. Use the-z parameter in tar to call gzip. The following is an example:
# Tar-czf all.tar.gz *. jpg
Bytes
# Tar-xzf all.tar.gz
This command unlocks the generated package.
2) tar call bzip2
Bzip2is a more powerful compression program. The file ending with .bz2 is the result of bzip2 compression. The decompress program relative to bzip2 is bunzip2. Use the-j parameter in tar to call gzip. The following is an example:
# Tar-cjf all.tar.bz2 *. jpg
Bytes
# Tar-xjf all.tar.bz2
This command unlocks the generated package.
3) tar call compress
Compress is also a compression program, but it seems that there are not as many people using compress as gzip and bzip2 .. The file ending with Z is the result of bzip2 compression. The decompress program relative to compress is uncompress. Use the-Z parameter in tar to call gzip. The following is an example:
# Tar-cZf all.tar. Z *. jpg
Forbidden. Z
# Tar-xZf all.tar. Z
This command is used to unbind the generated package.
With the above knowledge, you should be able to uncompress a variety of compressed files. The following is a summary of the compressed files in the tar series:
1st pair of files ending with .tar
Tar-xf all.tar
2XX for the file ending with .gz
Gzip-d all.gz
Gunzip all.gz
32.16.tgzor .tar.gz
Tar-xzf all.tar.gz
Tar-xzf all. tgz
4)for the file ending with .bz2
Bzip2-d all.bz2
Bunzip2 all.bz2
5 bytes for the file ending with tar.bz2
Tar-xjf all.tar.bz2
6) for files ending with. Z
Uncompress all. Z
72.16.tar. Z
Tar-xZf all.tar. z
Unzip command
Unzipcommand, which is used to extract a compressed file named. Zip.
Syntax: unzip [Option] compressed file name. Zip
The meanings of each option are as follows:
-X file list: Decompress the file, but does not include the specified file.
-V.
-T whether the test file is damaged, but the pressure is not solved.
-D directory: Decompress the compressed file to the specified directory.
-Z only displays the annotation of the compressed file.
-N does not overwrite existing files.
-O overwrites existing files and does not require user confirmation.
-J. Do not recreate the directory structure of the document and decompress all the files to the same directory.
Example 1: extract text.zip from the current directory.
$ Unzip text.zip
Example 2: Decompress the compressed file text.zip under the specified directory/tmp. If the same file already exists, the unzip command must not overwrite the original file.
$ Unzip-n text.zip-d/tmp
Example 3: view the directory of the compressed file.
$ Unzip-v text.zip
Gzip command
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
Meaning of each option:
-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 uncompressed files
Compression Ratio
Uncompressed file name
-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 uses the specified numeric num to adjust the compression speed.-1 or -- fast indicates the fastest compression method (low compression ratio), and-9 or -- best indicates the slowest compression method (high compression ratio ). The default value is 6.
Assume that a directory/homehas the mm.txtw.sort.txt and xx.com files.
Example 1: compress each file in the/homecatalog into A. GZ file.
$ Cd/home
$ Gzip *
$ Ls
M.txt.gz sort.txt.gz xx.com.gz
Example 2: extract each compressed file in Example 1 and list the detailed information.
$ Gzip-dv *
Mm.txt.gz 43.1% ----- replaced with mm.txt
Sort.txt.gz 43.1% ----- replaced with sort.txt
Xx.com.gz 43.1% ----- replaced with xx.com
$ Ls
Mm.txt sort.txt xx.com
Example 3: detailed information of each compressed file in Example 1 is displayed without decompression.
$ Gzip-l *
Compressed uncompr. ratio uncompressed_name
277 445 43.1% mm.txt
278 445 43.1% sort.txt
277 445 43.1% xx.com
$ Ls
Mm.txt.gz sort.txt.gz xx.com.gz
Example 4: compress a Tartar file, for example, usr.tar. the extension name of the compressed file is .tar.gz.
$ Gzip usr.tar
$ Ls
Usr.tar.gz