Access to the server through SSH, it is inevitable to use compression, decompression, packaging, unpack, etc., this time the tar command is essential to a powerful tool. The most popular tar in Linux is though small, spite, and powerful.
The tar command creates files for Linux files and directories. With tar, you can create files for a particular file (backup files), change files in your files, or add new files to your files. Tar was originally used to create files on tape, and now users can create files on any device. With the tar command, you can package a large number of files and directories into a single file, which is useful for backing up files or combining several files into a single file for easy network transmission.
The first thing to understand is two concepts: packaging and compression. Packaging refers to a large pile of files or directories into a total file, compression is a large file through some compression algorithm into a small file.
Why should we distinguish between these two concepts? This is because many of the compression programs in Linux can only compress a single file, so that when you want to compress a bunch of files, you have to first punch a stack of files into a package (the tar command), and then compress it (gzip bzip2 command).
The most common packaging program under Linux is tar, and the packages we use in the TAR program are often referred to as the TAR packets, and the TAR package file commands are usually ended with. Tar. After the tar package is generated, it can be compressed with another program.
1. Command format:
tar[necessary parameters [select parameters] [file]
2. Command function:
Used to compress and decompress files. Tar itself does not have a compression function. He's calling the compression function.
3. Command parameters:
The necessary parameters are as follows:
-A new compressed file to existing compression
-B Set Block size
-C To create a new compressed file
Differences between-D record files
-R adding files to already compressed files
-U adds changed and existing files to a compressed file that already exists
-X extracts files from compressed files
-T displays the contents of the compressed file
-Z supports gzip decompression files
-j Support bzip2 Extract files
-Z supports compress decompression files
-V Display Operation procedure
-L File System boundary settings
-K preserves existing files without overwriting
-M retention File not overwritten
-W confirm the correctness of the compressed file
The optional parameters are as follows:
-B Set the number of blocks
-c switch to the specified directory
-F Specify compressed files
--HELP Display Help information
--version Display version Information
4. Common decompression/Compression commands
Tar
Unpack: Tar xvf Filename.tar
Packing: Tar cvf filename.tar dirname
(Note: Tar is packed, 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