Linux compress command

Linux 命令大全Linux Command Collection

The Linux compress command is a rather old Unix file compression command. Compressed files are given a .Z extension to distinguish them from uncompressed files. Compressed files can be decompressed with uncompress. If you want to compress multiple files into a single compressed file, you must first tar the files and then compress them. Since gzip can produce better compression ratios, most people have switched to gzip as their file compression tool.

Syntax

compress [-dfvcV] [-b maxbits] [file ...]

Options:

  • c Output results to the standard output device (usually the screen)
  • f Force writing to the file; if the destination file already exists, it will be overwritten (force)
  • v Print the program execution messages on the screen (verbose)
  • b Set the upper limit of the number of common strings, calculated in bits, with values from 9 to 16 bits. Since the larger the value, the more common strings can be used, and the greater the compression ratio, so the default value of 16 bits is generally used (bits)
  • d Decompress the compressed file
  • V Print version information
  • Examples:
  • Compress source.dat into source.dat.Z. If source.dat.Z already exists, its contents will be overwritten by the compressed file.
  • compress -f source.dat
  • Compress source.dat into source.dat.Z, and print the compression ratio.
  • -v and -f can be used together
  • compress -vf source.dat
  • Output the compressed data and then redirect it to target.dat.Z to change the compressed file name.
  • compress -c source.dat > target.dat.Z
  • The larger the -b value, the greater the compression ratio. The range is 9-16, and the default value is 16.
  • compress -b 12 source.dat
  • Decompress source.dat.Z into source.dat. If the file already exists, the user presses y to confirm overwriting the file. If -df is used, the program will automatically overwrite the file. Since the system automatically adds .Z as the extension, source.dat is automatically treated as source.dat.Z.
  • compress -d source.dat
  • compress -d source.dat.Z

Compress file

[root@example.com ~]# compress abc.h
[root@example.com ~]# ls

abc.h.Z

Decompress file

[root@example.com ~]# compress -d abc.h.Z
[root@example.com ~]# ls

abc.h.

Compress with a specified compression ratio

[root@example.com ~]# compress -b 7 abc.h

Force compress folder

[root@example.com ~]# compress -rf /home/abc/ 

Linux 命令大全Linux Command Collection

Other extensions