YouTip LogoYouTip

Linux Comm Gzip

Linux gzip Command

Linux gzip Command

--

Linux Tutorial

Linux Tutorial Linux Introduction Linux Installation Linux Cloud Server Install Linux via WSL Linux System Boot Process Linux System Directory Structure Linux Forgot Password Solution Linux Remote Login Linux File Basic Attributes Linux File and Directory Management Linux User and User Group Management Linux Disk Management Linux vi/vim Linux yum Command Linux apt Command

Shell Tutorial

Shell Tutorial Shell Variables Shell Passing Arguments Shell Arrays Shell Operators Shell echo Command Shell printf Command Shell test Command Shell Flow Control Shell Functions Shell Input/Output Redirection Shell File Inclusion

Linux Reference Manual

Linux Command Complete List Nginx Installation and Configuration MySQL Installation and Configuration Linux Quiz

Shell File Inclusion

Nginx Installation and Configuration

Deep Dive

Software

Scripting Languages

Network Design and Development

Computer Science

Scripting

Web Services

Web Service

Programming Languages

Programming

Development Tools

Linux gzip Command

Linux Command Complete List Linux Command Complete List

The Linux gzip command is used to compress files.

gzip is a widely used compression program. After a file is compressed by it, its name will have an additional .gz extension.

gzip uses the DEFLATE compression algorithm, which is usually faster than bzip2 but has a slightly lower compression ratio.

Syntax

gzip  [file...]
  • file...: The files to be compressed. gzip will compress the specified files, generate a compressed file with a .gz suffix, and delete the original files.

Options Parameters:

  • -d: Decompress .gz files. Equivalent to using the gunzip command.
  • -k: Keep the original file, do not delete it.
  • -r: Recursively compress all files in the directory.
  • -v: Display detailed compression or decompression process.
  • -l: Display detailed information about the compressed file, such as compression ratio, original size, etc.
  • -1 to -9: Specify compression ratio. -1 is the fastest compression with the lowest compression ratio; -9 is the slowest compression with the highest compression ratio. The default is -6.
  • -t: Test the integrity of the compressed file.

Examples

Compress a File

gzip example.txt

This command will compress example.txt to example.txt.gz and delete the original file example.txt.

Keep the Original File

If you want to keep the original file after compression, you can use the -k option:

gzip -k example.txt

This command will keep the original example.txt file and generate example.txt.gz.

Decompress a File

To decompress a .gz file, you can use the -d option or use gunzip directly:

gzip -d example.txt.gz

or

gunzip example.txt.gz

This will decompress example.txt.gz back to the original example.txt file.

Recursively Compress a Directory

You can use the -r option to recursively compress an entire directory:

gzip -r directory/

This command will compress all files in the directory directory and preserve the directory structure.

Display Compressed File Information

Use the -l option to view detailed information about a .gz file:

gzip -l example.txt.gz

This command will display information such as the file's original size, compressed size, compression ratio, etc.

Test a Compressed File

Use the -t option to test the integrity of a compressed file:

gzip -t example.txt.gz

If the file is intact and undamaged, this command will have no output; otherwise, it will prompt an error.

gzip is mainly used to compress single files. If you need to compress multiple files or an entire directory, it's common to first archive them with tar, then compress with gzip. For example:

tar -cvzf archive.tar.gz directory/

Linux Command Complete List Linux Command Complete List

← Linux Comm LhaOs Major β†’