Tar application in Linux

Source: Internet
Author: User
Tags rar extension uncompress

Original English meaning: tape archive

Chinese meaning: tape Archiving
Note
Solution: A file packaging tool in Unix/Linux is used to pack many files together to form an archive file for archiving. It was originally designed for tape backup and can now be used for other storage services
Quality. A file with the extension of .tar is generated when it is used only. When combined with gzipfor data compression, the generated file extension name can be .tgz).tar.gz or
When combined with data compression, the generated file extension name is .tar. Z.
Tar command
Purpose
Process archiving.
Syntax
Tar {-c |-r |-T |-u |-x} [-B Blocks
] [-B] [-D] [-F] [-H] [-I] [-l inputlist] [-L] [-M] [
-N blocks] [-O] [-p] [-S] [-V] [-W] [-number] [-F Archive
] [-S blocksb |-s feet @ density] [file | directory |-C
Directory]...
Description
Note: Due to the limitation of the first block space in the tar command, when it is restored to some systems, the user number (UID) and group ID (GID) greater than 65,535 will be destroyed. Size constraints only affect ownership and permission, and do not cause damage to Data. The destruction of ownership occurs in the following systems:
* The uname and gname fields are not used to check ownership systems.
* The system does not have the same user and group ID as the archive system.
Note:
1. The USTAR Header Format allows the file size to 8 GB. Therefore, the tar command supports archiving files up to 8 GB.
2. Tar does not retain the sparse attribute of any sparse files. Any file that is originally sparse before restoration will be allocated all its space in the file system according to the file size.
The tar command writes an object to the archive storage media or retrieves the object from the media to archive the object. Files used by the tar command are represented by the file parameter. If the file parameter references a directory, the directory is referenced and all files and directories under the directory are recursively referenced.
The tar command searches for archives on the default device (usually tape) unless the-F archive flag is used to specify another device. When you specify a path name with more than 100 characters for the USTAR format, remember that the path name is a prefix buffer, A/(slash) and a name buffer.
The prefix buffer can contain a maximum of 155 bytes, while the name buffer can contain a maximum of 100 bytes.
Bytes. If the path name cannot be separated by a slash, it cannot be archived. This restriction takes tar into account.
The structure of the archive header, which must be maintained to comply with standards and backward compatibility. In addition, the target length of a hard link or symbolic link ("Link name") cannot exceed 100 bytes.
When writing to the archive, the tar command uses a temporary file (/tmp/tar * file) and maintains a table containing multi-link files in the memory. If the tar command cannot create temporary files, or there is not enough memory to store the chain table, you will receive an error message.
The tar command has two sets of labels: required and optional. The flag is required to control the operations of the tar command, including-C,-R,-T,-u, and-X. To execute the tar command, select at least one required flag. After you select the required flag, you can select an optional flag, but they are not necessary to control the tar command.
Note:
1. When the storage device is a common file or a special block file, the-U and-R signs can be unsigned. However, the original tape device does not support backspace. Therefore, when the storage device is a raw tape, the-U and-R flags carry out the rewind, open the tape, and read the tape again.
2. The length of a block tape record is one piece, but they are usually less than half of the density on the original tape. Therefore, although the original tape by block record must be read twice, the total movement of the tape is less than that of a single record by block record.
3. The structure of the streaming tape device does not support adding information at the end of the tape. Therefore, the-U and-R flags are not valid when the storage device is a streaming tape. Attempting to use these flags will result in the following error messages:
Tar: the update and replacement options are invalid for streaming tape drives.
4. The tape error cannot be recovered.
5. You can change the default block size to improve the performance of the tar command on the IBM 9348 tape drive 12. To change the block size, enter the following command on the command line:
Chdev-1 & lt; device_name & gt;-A block_size = 32 K
For more information about using tape devices, see RMT special files.
Flag
The tar command has two groups of signs, required and optional. You must provide at least one required flag to control the tar command.
Required flag
-C create a new archive and write the file specified by one or more file parameters to the beginning of the archive.
-R writes the file specified by one or more file parameters to the end of the archive. This flag is not valid for any tape device because some devices do not support adding information at the end of the tape.
-T List objects in the archive order. Files may be listed multiple times.
-U writes files (specified by one or more file parameters) to the end of the archive only when they are not archived or modified after they are written to the archive. -U flag is not valid for any tape device because some tape devices do not support adding information at the end of the tape.
-X extracts one or more files specified by the file parameter from the archive. If file
A parameter is a directory. the tar command recursively extracts the directory from the archive. If you do not specify the file parameter, tar
Command to extract all files from the archive. If the archive contains multiple copies of the same file, the last extracted copy overwrites all previously extracted copies. If the extracted file does not exist in the system, create the file
. If you have the appropriate permission, tar
Command to restore all files and directories with the same owner and group ID as the tape. If you do not have proper permissions, files and directories will be restored with your owner ID and group identity. Only the last version of the file can be requested
.
Optional flag
-B: the input and output parts must be 20 for each record. With this option, the tar command can be executed between communication channels that may not maintain blocks.
-B blocks indicates the number of 512 bytes for each record. The default value and maximum value are both 20, which is the appropriate number of tapes. Because of the record gap size, a tape written with a large block factor can save more data than a tape with only one record.
When the tape is read, the block size is automatically determined (-X or-T ). The existing record size is used when the archive is updated by-U and-R. Only when the-C flag is used to create a new archive, the tar command uses the value specified by the blocks parameter to write data to the archive.
When the-F mark is used to output data to a common file, you can use the block factor that matches the disk block size to save disk space (for example, for a 2048-byte disk block, use the-B4 flag ).
-C Directory: run the tar command to the directory specified by the Directory variable.
Chdir subroutine. Use the-C flag to allow multiple directories associated with the archive without similar public parent directories. Use a short relative path name. For example
And/etc directory, you can use the following command:
Tar c-c/usr/include file1 file2-C/etc file3 file4
The-C directory flag must appear after all other marks, or in the given file name list.
-D creates separate entries for block files, special character files, and first-in-first-out (FIFO) pipeline processes. In general, the tar command does not archive these special files. When the-D mark is used to write data to the archive, the tar command enables the archive to use the-X mark to restore the empty directory, special files, and first-in-first-out (FIFO) pipeline processes.
Note:
Although anyone can archive special files, only users with root user permissions can extract special files from the archive.
-F check the file type before archiving. Source code control system (SCCS), Revision Control System (RCS), files named core, errs, and A. Out, and files ended at. O (point O) are not archived.
-F archive: Use Archive
Variable indicates the archive to be read or written. If this flag is not specified, the tar command uses a default file name (in the format of/dev/rmt0) for a specific system ). If the specified
The archive variable is-(minus sign). The tar command is written to the standard output or read from the standard input. To write standard output data, you must use the-C flag.
-H forces the tar command to monitor symbolic links, as if they were regular files or directories. Generally, the tar command does not monitor symbolic links.
-I ignore header checksum errors. Tar
Command to write a file header in the archive, which contains the checksum of each file. If this flag is not specified, the system re-calculates the checksum to verify the content of the header block, stops and reports the directory School
Verification and error. If this flag is specified, tar
The Command records errors and then scans forward until a valid header block is found. This allows you to restore files from the back of the multi-volume archive without reading the previous volume.
-L inputlist: The inputlist parameter of the-L option should always be a file name, which lists the files and directories to be archived.
Similarly, the inputlist parameter can be a variable that stores the name of a file. This variable lists the files and directories to be archived.
This option helps archive the files and directories listed in the inputlist parameter. The directory in the inputlist parameter is not recursive. For the directory contained in the inputlist parameter, the tar command only writes the directory to archive, instead of writing the files and subdirectories in the directory to archive.
If the additional files and directories follow the inputlist parameter in the command line, the content of the inputlist parameter is archived after these files and directories. These additional files or directories are archived based on their default behavior, recursively archiving them.
-L for each link with more than 1
But the corresponding link is not archived, and the error message is written to the standard output. For example, if file1 and file2 are hard-linked together
If it is stored in the archive, the-l flag sends an error message. If the-l flag is not specified, no error message is displayed.
-M uses the extraction time as the modification time. The default value is the modification time of the retained file.
-N blocks when tar
The command allows a large block cluster to be used when processing streaming tape archives. However, note that when you enter a large block size
The command will not automatically determine the size of the tape block. If the-n blocks flag is not displayed, the tar command automatically determines that the maximum block size is 20.
-O provides backward compatibility with the earlier version (non-Aix) tar command. When this flag is used for reading, the extracted files use the user ID and group ID (UID and GID) of the running program, rather than the user ID and group ID in the archive. This is the default behavior for common users.
-P restores fields to their original method, ignoring the existing user permission shielding bit (umask ). Setuid, setgid, and tacky bit permissions are also restored to users with root user permissions. This indicates that the file is restored to its original method, but the directory is not restored to its original method.
-S if the tar command fails to use the-s flag to successfully attempt to link (regular link) Two files, try to create a symbolic link.
-Sblocksb,-s feet,-s feet @ density specifies
The number of KB blocks (the first format) does not depend on the tape partition factor. You can also use the second format to specify the tape size in feet. In this case, tar
Command to assume a default density variable. The third format allows you to specify the tape length and density. Feet are conservatively assumed to be 11
Inches long. This flag makes it easier for you to archive multiple volumes of tape. In this case, the tar command must be able to determine how many pieces can be placed per volume.
Note:
1. The density of the tape drive varies. The amount of data that the density variable computing system can put on tape.
2. If you use a 4 inch/tape device, you must consider the number of tracks on the tape device when specifying the feet variable value. For example, you can use the-s feet @ density flag to specify a 4-track, 1/600 feet tape drive with a density of 8000 tapes and 4 inch Bytes/inch, as shown below:
-S 2400 @ 8000
Here, multiply 600 feet by 4 magnetic channels to 2400 feet.
-V lists their names when processing each file. With the-T flag,-V provides more information about the tape entry, including the file size, last modification time, user ID (UID), group ID (GID), and permission.
-W shows the operation to be performed, followed by the file name, and then waits for the user to confirm. If the answer is yes, perform the operation. If the answer is not correct, ignore the file.
-Number: Use the/dev/rmtnumber file instead of the default value. For example, the-2 flag is the same as the-F/dev/rmt2 file.
Exit status
This command returns the following exit values:
0.
& Gt; 0 indicates an error occurred.
Example
1. To write file1 and file2 files to a new archive on the default drive, enter:
Tar-C file1 file2
2. to extract all files in the/tmp directory from the archive files on the/dev/rmt2 tape device and use the extraction time as the modification time, enter:
Tar-XM-F/dev/rmt2/tmp
3. To create an archive file that contains file1 and pass the archive file to the DD command to write it to the/dev/rmt1 device, enter:
Tar-CVF-file1 | dd OF =/dev/rmt1 Conv = sync
4. to display the names of each file in the out.tar disk archive file in the current directory, enter:
Tar-VTF out.tar
5. Extend the compressed tar archive file, fil.tar. Z, transfer the file to the tar command, and extract all the files from the expanded tar archive file. Enter:
Zcat fil.tar. z | tar-xvf-
6. to archive the/usr/include and/usr/bin files with a short relative path name, enter:
CD/usr
Tar-CVF/dev/rmt0-C./include.-C ../bin.
Note:
When the relative path name is used to specify multiple instances with the-C flag, you must consider the previous-C flag request.
7. to archive to a 8mm device when the-s flag is used, enter:
Tar-CVF/dev/rmt0-s 4800000b/usr
Note:
When archiving to 8mm devices, the-s feet and-s feet @ density labels are not recommended because 8mm devices do not use the density concept when writing tape.
8. to archive a list Of all c files (these files are listed in the file using the inputlist parameter of the-L option), enter:
Tar-CVF fl.tar-l fl_list
Here, fl_list is a file that contains a list of all. c files. This can be obtained through the following command:
Ls *. C & gt; fl_list
9. To use the-L option to set a variable to archive a list Of all c files, enter:
Ls *. C & gt; fl_list
FL = fl_list
Tar-CVF var.tar-L $ fl
File
/Dev/rmt0 specifies the default tape device.
/Bin/tar specifies the symbolic link of the tar command.
/Usr/bin/TAR contains the tar command.
/Tmp/tar * specifies the temporary file.
==================================
  Tar is a package program in Linux, or a compression format.

The compressed format in linuxis .gz).tar.gz?tgz=bz2}.z}.tar. tar is one of them.
Before we talk about Linux compressed files, we must first
Clarify two concepts: Packaging and compression. Packaging refers to converting a large number of files or directories into a total file. Compression refers to converting a large file into a small file through some compression algorithms. Why distinguish this?
What are the two concepts? In fact, this is because many Linux compression programs can only compress one file, so when you want to compress a large number of files, you must first use another tool to compress these files first
Into a package, and then compress the original compression program.
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 files in the all.tar package.-X is used to unlock the file.
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 people who use compress are not as good as gzip and
Bzip2 has many people .. The file at the end of Z is the end of Bzip2 compression.
Result. 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
In addition, Linux has corresponding methods to decompress the compressed files .zipand .rar in Windows:
1)for. Zip
Linux provides zip and unzip programs, Zip is a compression program, and unzip is a decompression program. They have many Parameter options. Here we will only give a brief introduction and give examples to illustrate their usage:
# Zip all.zip *. jpg
This command compresses all .jpg files into a zip package.
# Unzip all.zip
This command decompress all files in all.zip.
2XX vs. .rar
To process the. rar file in linux, you need to install RAR for Linux, which can be downloaded from the Internet, but remember, rar for Linux
Not free; then install:
# Tar-xzpvf rarlinux-3.2.0.tar.gz
# Cd RAR
# Make
After installation, there will be two programs, RAR and unrar. rar is a compression program, and unrar is a decompression program. They have many Parameter options. Here we will only give a brief introduction and give examples to illustrate their usage:
# Rar a all *. jpg
This command is to compress all. jpg files into a rarpackage named all.rar. the program will automatically append the. rar extension name to the package name.
# Unrar e all.rar
This command is to extract all files from all.rar.
So far, we have introduced tar, Gzip, gunzip, Bzip2,
Bunzip2, compress, uncompress,
Success ,.
These 10 types of compressed files, zw..tar.zw..zipw.rar, have been decompressed. In the future, you should not have to worry about downloading a software and not knowing how to unbind it in Linux. In addition
Method is also basically effective for Unix.
  To sum up, some common commands for compression and decompression in Linux:

Compression
Tar-CVF jpg.tar *. jpg // pack all JPG files in the Directory into tar.jpg
Tar-CZF jpg.tar.gz *. jpg // JPG
Tar-CJF jpg.tar.bz2 *. jpg // JPG
Tar-CZF jpg.tar. z *. jpg // JPG. Z
Rar a jpg.rar *. jpg // RAR format compression, You need to download RAR for Linux
Zip jpg.zip *. jpg // ZIP format compression, You need to download zip for Linux first
Extract
Tar-xvf file.tar // decompress the tar package
Tar-xzvf file.tar.gz // decompress tar.gz
Tar-xjvf file.tar.bz2 // unzip tar.bz2
Tar-xzvf file.tar. Z // extract tar. Z
Unrar e file.rar // extract RAR
Unzip file.zip // decompress the ZIP file
==================================
There is also a software testing tool
It is also called Tar. It is a terminal testing tool.
The following is a detailed introduction.
Terminal autorunner
Applicable to standard application systems such as VT100 and vt220, and supports command line and window modes (applications written using cursors ).
Supports automatic recording of terminal applications. Supports continuous recording and separate window recording. Supported window components: bar, table, dialog box, window, etc.
The scripting language adopts Java standard Script: bean shell.
You can modify the recorded resources as "WYSIWYG", including redefining components, modifying component attributes, and deleting components.
Provides Virtual Device plug-ins for terminal devices, such as terminals, cryptographic keyboards, card readers, and credential printers. When testing the application system, the tested system can still use devices without modifying the code.
You can connect to the test management tool separately.
It can also be used as a plug-in for testing tools and is widely used in terminal testing.

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.