Linux compress Command
The Linux compress command is an old Unix file compression utility. Compressed files are appended with a .Z extension to distinguish them from uncompressed files, and can be decompressed using uncompress. To compress multiple files into one archive, you must first tar the files before compressing. Due to gzip providing better compression ratios, most people have switched to using gzip for file compression.
Syntax
compress [-dfvcV] [-b maxbits] [file ...]
Parameters:
c Outputs the result to the standard output device (usually the screen)
f Forces the file to be written, overwriting the destination file if it already exists (force)
v Prints program execution messages on the screen (verbose)
b Sets the upper limit for the number of common strings, measured in bits, with values ranging from 9 to 16 bits. Since a larger value allows more common strings and better compression ratios, the default is usually set to 16 bits (bits)
d Decompresses the compressed file
V Displays version information
Examples:
Compresses source.dat into source.dat.Z. If source.dat.Z already exists, its contents will be overwritten.
compress -f source.dat
Compresses source.dat into source.dat.Z and prints the compression ratio.
-v and -f can be used together
compress -vf source.dat
Compresses the data and outputs it before redirecting to target.dat.Z, which changes the compressed file name.
compress -c source.dat > target.dat.Z
The larger the value of -b, the better the compression ratio, with a range of 9-16, and the default value is 16.
compress -b 12 source.dat
Decompresses source.dat.Z into source.dat. If the file already exists, the user is prompted to confirm overwriting the file with 'y'. Using -df will automatically overwrite the file. Since the system automatically adds .Z as an extension, source.dat will be automatically treated as source.dat.Z.
compress -d source.dat
compress -d source.dat.Z
Compressing Files
[root@tutorialpro.org ~]# compress abc.h
[root@tutorialpro.org ~]# ls
abc.h.Z
Decompressing Files
[root@tutorialpro.org ~]# compress -d abc.h.Z
[root@tutorialpro.org ~]# ls
abc.h.
Compressing with a Specified Ratio
[root@tutorialpro.org ~]# compress -b 7 abc.h
Forcibly Compressing a Directory
[root@tutorialpro.org ~]# compress -rf /home/abc/