compress command in Linux with examples

compress command is used to reduce the file size. After compression, the file will be available with an added .Z extension. File permissions will still remain the same as before using compress command. This command uses the adaptive Lempel-Ziv coding and it ignores the symbolic links. And also this command is part of ncompress package, which contains utilities for fast compression and decompression.

Note: If no files are specified then the standard input is compressed to the standard output.

Syntax:

compress [OPTION]... [FILE]...

Options:

  • -v Option: It is used to print the percentage reduction of each file. This option is ignored if the -c option is also used. Compress example.xls and rename that file to example.xls.Z with a percentage reduction of 70.41%.
    compress -v example.xls
    

  • -c Option: Compressed or uncompressed output is written to the standard output. No files are modified. The -v option is ignored. Compression is attempted even if the results will be larger than the original.

    Example:

    compress -c example.xls > new.Z
    

  • -r Option: This will compress all the files in the given directory and sub-directories recursively. It is helpful to combine the -r option with -v to see exactly what the command is doing.

    Example:

    compress -rv abc
    

    This will compress all the files within abc.

  • -f Option: This will compress files without any guarantee of size reduction, meaning it will compress files even if the file size is not reduced.
    compress -f asc.txt
    

    This will convert asc.txt into asc.txt.Z but size reduction is not assured.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.