Linux compress Command
The Linux compress command is a rather old Unix archive compression utility. Compressed archives are given a .Z extension to distinguish them from uncompressed files, and can be decompressed with uncompress. To compress several files into one archive, you must first tar the files and then compress them. Since gzip produces a better compression ratio, most people have switched to gzip as their compression tool.
Syntax
compress [-dfvcV] [-b maxbits] [file ...]
Parameters:
- c output the result to standard output (usually the screen)
- f force writing to the archive; if the destination file already exists, it will be overwritten (force)
- v print program execution messages on the screen (verbose)
- b set the upper limit of the number of common strings, measured in bits; the value can range from 9 to 16 bits. 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 an archive
- V list version information
- Example:
- Compress source.dat into source.dat.Z; if source.dat.Z already exists, its contents will be overwritten by the compressed archive.
- 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
- Redirecting the compressed data and then writing it into target.dat.Z can change the archive name.
- compress -c source.dat > target.dat.Z
- The larger the value of -b, the greater the compression ratio; the range is 9-16, and the default 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; if -df is used, the program overwrites the file automatically. Since the system automatically adds the .Z extension, source.dat is treated as source.dat.Z.
- compress -d source.dat
- compress -d source.dat.Z
Compress a file
[root@runoob.com ~]# compress abc.h [root@runoob.com ~]# lsabc.h.Z
Decompress a file
[root@runoob.com ~]# compress -d abc.h.Z [root@runoob.com ~]# lsabc.h.
Compress with a specified compression ratio
[root@runoob.com ~]# compress -b 7 abc.h
Force compression of a folder
[root@runoob.com ~]# compress -rf /home/abc/
Linux Command Reference