linux--Compressed Files

Source: Internet
Author: User
Tags numeric value

linux--Compressed Files

Why do I need to compress files?
The file may take too much time to transfer due to the large file size during the transfer process. There are two obvious benefits to reducing file size, one is the ability to reduce
Less storage space, the second is to transfer files over the network, you can reduce the transmission time. For some infrequently used files, reduce it to hard disk space
Waste, we tend to compress it and decompress it when needed.


What file compression commands are available in Linux?
In Linux, a lot of file compression commands are provided, and we can choose different compression methods for the files that need to be compressed.
Compression format: gz bz2 xz zip Z
Compression ratios are different depending on the compression algorithm.

The compression command is detailed:

Gzip:FILE.gz
Gzip can be used not only to compress large, less-used files to conserve disk space, but also to form a Linux operating system with the TAR command
Compare the popular compressed file formats. According to statistics, the gzip command has a 60%~70% compression rate for text files.

Syntax format: gzip option parameter

Common options:
-A or--ascii: use ASCII text mode;
-D or--decompress or----uncompress: unpack the compressed file;
-F or--force: Forcibly compress the file. Ignores the existence of a file name or a hard connection and whether the file is a symbolic connection;
-L or--list: Lists information about compressed files;
-N or--no-name: When compressing a file, the original file name and time stamp are not saved;
-N or--name: When compressing the file, save the original file name and time stamp;
-Q or--quiet: No warning message is displayed;
-R or--recursive: recursively handles all files and subdirectories under the specified directory;
-S or < compress the tail string > or----suffix< compress the tail string;: Change the compressed word tail string;
-T or--test: Test whether the compressed file is correct;
-#< Compression ratio is a numeric value between 1~9, the default value is 6, the higher the specified value, the higher the compression efficiency;
--best: The effect of this parameter is the same as specifying the "-9" parameter;
--fast: The effect of this parameter is the same as specifying the "-1" parameter.

[[email protected] scourse]$ ls
passwd
[[Email protected] scourse]$ gzip *
[[email protected] scourse]$ ls
Passwd.gz
[Email protected] scourse]$ gzip-d *
[[email protected] scourse]$ ls
passwd

By default, the source file is deleted when it is finished compressing

Zcat: In the case of decompression, view the contents of the text file that was compressed by gzip.


bzip2:FILE.bz2
BZIP2 has a greater compression ratio than gzip, using a format approximation.
Syntax format: bzip2 option parameter
Common options:
-C or--stdout: The results of compression and decompression are sent to standard output;
-D or--decompress: Perform decompression;
-F or-FORCE:BZIP2 when compressing or decompressing, if the output file has the same name as an existing file, the preset does not overwrite the existing file. to overwrite. Please use this parameter;
-K or--keep:bzip2 deletes the original file after it is compressed or uncompressed. To keep the original file, use this parameter;
-S or--small: Reduce the amount of memory used during program execution;
-V or--verbose: Displays detailed information when compressing or decompressing a file;
-Z or--compress: enforces compression;
-#< Compression ratio is a numeric value between 1~9, the default value is 6, the higher the specified value, the higher the compression efficiency;

BUNZIP2 files: extracting. bz2 files

Bzcat: View the contents of the bzip2 text file without being pressed.


Xz:FILE.xz
Greater compression ratio
Syntax format: XZ option parameter
Common options:
-D: Unzip
-#< Compression ratio is a numeric value between 1~9, the default value is 6, the higher the specified value, the higher the compression efficiency;
-K: Preserve source files while compressing, or use output redirection to preserve source files

UNXZ: Decompression

Xzcat: In the case of no pressure, view the contents of the XZ text file, with Xzdec


Zip: Can be used to unzip a file, or to package a file. Zip is a widely used compression program that compresses the file and then
Produces a compressed file with a ". zip" extension.

Syntax format: Zip compressed file name to be compressed

Common options:
-A: Adjust the executable automatic decompression file;
-b< working directory;: Specifies the directory where files are temporarily stored;
C: Add comments for each compressed file;
-D: Deletes the specified file from the compressed file;
-D: The directory name is not established within the compressed file;
-F: The effect of this parameter is similar to specifying the "-u" parameter, but not only updates the existing file, if some files do not originally exist in the compressed
In the file, the use of this parameter will be added to the compressed file;
-F: Attempt to repair corrupted compressed file;
-G: The file is compressed and appended to the existing compressed file, instead of creating a new compressed file;
-i< template style;: Only the files that match the conditions are compressed;
-j: Save only the file name and its contents, not the name of any directory;
-J: Delete unnecessary data in front of compressed file;
-K: File name using MS-DOS compatible format;
-L: Replace LF characters with LF+CR characters when compressing files;
-ll: When compressing a file, replace the LF+CP character with the LF character;
-M: When the file is compressed and added to the compressed file, the original file is deleted and the file is moved to the compressed file;
-n< string;: Do not compress files with a specific string of characters;
-O: The file with the most recent change in the compressed file, the change time of the compressed file is set to the same as the file;
-Q: Do not display the instruction execution process;
-R: Recursive processing, all files and subdirectories under the specified directory are processed together;
-S: Contains system and hidden files;
-t< date time;: Set the date of the compressed file to the specified date;
-T: Check that each file in the backup file is correct;
-U: Replace the newer files in the compressed file;
-V: Displays the instruction execution process or displays the version information;
-V: Saves the file attributes of the VMS operating system;
-W: If the version number is in the file name, this parameter is only valid under the VMS operating system;
-x< template style;: Exclude files that meet the conditions when compressing;
-X: Do not save additional file attributes;
-Y: Save the symbolic connection directly, not the file that the link points to, this parameter is only valid under a system such as UNIX;
-Z: Add comments for compressed files;
-$: The name of the volume of the disk on which the first compressed file is stored;
-< Compression ratio: The compression ratio is a value between 1~9.

Unzip: Decompression


What is the difference between packing and compressing?
Packaging refers to a large number of files or directories into a total file, compression is a large file through some compression algorithm into a small file.


Why should we differentiate between these two concepts?
This is due to the many compression programs in Linux that can only be compressed for one file, so that when you want to compress a lot of files, you have to put this whole bunch of
The file is first punched into a package (Tar command) and then compressed (gzip, bzip2 command).


Archive tool:
Tar: Default does not store extended properties
With tar, you can create files (backup files) for a specific file, or you can change files in your file, or add new
File. With the tar command, you can package a whole bunch of files and directories into a single file, which is for backing up files or combining several files
It is very useful to be a file to facilitate network transmission.

Syntax format: tar option parameter

Common options:
-C: Create an archive file
-X: Expand Archive file
-F: Manipulating archive files
--xattrs: Preserve file extension property information when archiving
-T: Do not expand the archive to see only which files are archived
-ZCF: Archive and invoke gzip compression
-ZXF: Call gzip compression and re-archive
-JCF: Archive and call bzip2 compression
-JXF: Call bzip2 Compress and re-archive
-JCF: Archive and invoke XZ compression
-JXF: Call XZ compression and re-archive

Cpio: Archive Tool

linux--Compressed Files

Related Article

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.