Compress files or directories in Linux. We will learn the basic usage of zip, tar, tar.gzand tar.bz2 compression formats.
ZIP format has become the standard choice for compressed files, and it can also be used on Windows.
Files that need to be shared to Windows users are often compressed in ZIP format.
If you only share the data to the linuxlinuxuser, you can select the tar.gz format.
Zip
Zip may be the most commonly used File compression format. It is used on different operating system platforms, such as Linux, windows, and Mac OS. The compression rate is not very high, and tar.gzand tar.gz 2 are very good in terms of compression rate.
Compress a directory:
# Zip-r archive_name.zip directory_to_compress
Below is a zip file:
# Unzip archive_name.zip
Tar
Tar is a widely used document packaging format in Linux. Its advantage is that it only consumes a very small amount of CPU and time to package files. It is only a packaging tool and is not responsible for compression.
The following shows how to package a directory:
# Tar-CVF archive_name.tar directory_to_compress
How to unpack:
# Tar-xvf archive_name.tar.gz
The preceding command unpacks the document in the current directory. Of course, you can also use this command to determine the path for unpacking:
# Tar-xvf archive_name.tar-C/tmp/extract_here/
Tar. GZ
This format is the most commonly used compression format. It does not occupy too much CPU during compression, and can obtain an ideal compression rate.
Use the following format to compress a directory:
# Tar-zcvf archive_name.tar.gz directory_to_compress
Decompress:
# Tar-zxvf archive_name.tar.gz
The preceding command unpacks the document in the current directory. Of course, you can also use this command to hold the path for unpacking:
# Tar-zxvf archive_name.tar.gz-C/tmp/extract_here/
Tar. bz2
This compression format is the best compression ratio among all the methods we mentioned. Of course, this means that it takes more CPU and time than the previous method. For example, you can use tar.bz2 for compression.
# Tar-jcvf archive_name.tar.bz2 directory_to_compress
The preceding command unpacks the document in the current directory. Of course, you can also use this command to hold the path for unpacking:
# Tar-jxvf archive_name.tar.bz2-C/tmp/extract_here/
Data Compression is very useful, especially for backup. Therefore, you should now consider using the compression method you learned here in your backup script to back up your basic rule file to reduce the size of your backup file.
The tar command does not support compression. It is just a package command. In many cases, tokens are abbreviated as tgz.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wby0322/archive/2010/03/02/5338621.aspx