gzip is a compression utility that is used to compress and decompress files. It is based on the DEFLATE algorithm and is used to compress files to reduce their size, thereby saving disk space and reducing the time it takes to transfer files over a network. The gzip utility is commonly used in conjunction with the tar command to create compressed archive files.
Basic Syntax
gzip [options] [target ...]
Here, options are the various flags used to specify the compression level, verbosity, and other parameters. target is the file name or list of file names to be compressed.
Commonly Used Options
-
-c: This option writes the compressed output to the standard output, allowing it to be piped to another command or written to a file. -
-d: This option decompresses the specified file(s). -
-f: This option forces compression or decompression even if the output file already exists. -
-k: This option keeps the original file(s) after compression or decompression, instead of deleting them. -
-l: This option lists the compression ratio and size of the compressed file(s). -
-n: This option specifies the number of compression threads to be used. -
-r: This option recursively compresses or decompresses files in subdirectories. -
-v: This option displays verbose output.
Useful Examples
-
gzip file.txt: This compresses thefile.txtfile and replaces it with a compressed version of the file. -
gzip -k file.txt: This compresses thefile.txtfile but keeps the original file as well. -
gzip -d file.txt.gz: This decompresses thefile.txt.gzcompressed file and replaces it with the original file. -
gzip -r folder: This recursively compresses all files in thefolderdirectory and its subdirectories. -
gzip -c file.txt > file.txt.gz: This compresses thefile.txtfile and writes the compressed output to thefile.txt.gzfile. -
gzip -l file.txt.gz: This lists the compression ratio and size of thefile.txt.gzcompressed file. -
gzip -vf file.txt: This compresses thefile.txtfile and displays verbose output.
Leave a Reply