Gzip Command in Linux - GeeksforGeeks (2024)

Last Updated : 12 Jul, 2024

Summarize

Comments

Improve

gzip command compresses files. Each single file is compressed into a single file. The compressed file consists of a GNU zip header and deflated data. If given a file as an argument, gzip compresses the file, adds a “.gz” suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to the standard output.

Basics of gzip:

Gzip, short for GNU Zip, is a command-line compression tool commonly found on Linux systems. It utilizes the DEFLATE compression algorithm to reduce the size of files, making them more manageable for storage and transmission.

Table of Content

  • Basics of gzip:
  • Difference between Gzip and zip command in Unix and when to use which command
  • Syntax of the gzip Command
  • Options Available in gzip Command
  • Basic Compression using gzip Command in Linux
  • How to decompress a gzip file in Linux?
  • Keeping the Original File Using gzip Command in Linux
  • Verbose Mode Using gzip Command in Linux
  • Force Compression Using gzip Command in Linux
  • Compressing Multiple Files Using gzip Command in Linux
  • Recursive Compression with find Using gzip Command in Linux

Difference between Gzip and zip command in Unix and when to use which command

Feature

Gzip

Zip

Compression Algorithm

Uses the DEFLATE algorithm.

Uses various compression algorithms, including DEFLATE, LZ77, and others.

File Format

Typically appends “.gz” to compressed files.

Uses “.zip” extension for compressed archives.

Archiving Approach

Common practice is to use tarball (.tar) before compression.

Compresses individual files and then adds them to the archive.

File Extraction

Requires decompression of the entire file before extracting specific files.

Allows direct extraction of individual files without full decompression.

Compression Efficiency

Generally offers better compression, especially for a large number of files.

Compression efficiency may vary, and it might be less effective than Gzip for certain scenarios.

Extraction Time

Takes longer to extract a specific file from a compressed archive.

Allows quicker extraction of individual files from the archive.

Ideal Use Case

Well-suited for compressing a large number of files into a single archive.

Suitable for compressing and archiving individual files with a focus on easy extraction.

Redundancy Utilization

Efficiently utilizes redundancy in files to reduce overall file size.

May result in larger archive sizes, especially when compressing identical files multiple times.

Syntax of the gzip Command

The basic syntax of the gzip command is straightforward:

 gzip [Options] [filenames]

This syntax allows users to compress a specified file. Now, let’s delve into some practical examples to illustrate the usage of the gzip command.

Options Available in gzip Command

Options

Description

-f

Forcefully compress a file even if a compressed version with the same name already exists.

-k

Compress a file and keep the original file, resulting in both the compressed and original files.

-L

Display the gzip license for the software.

-r

Recursively compress all files in a folder and its subfolders.

-v

Display the name and percentage reduction for each file compressed or decompressed.

-d

Decompress a file that was compressed using the gzip command.

Basic Compression using gzip Command in Linux

To compress a file named “mydoc.txt,” the following command can be used:

Example:

gzip mydoc.txt

This command will create a compressed file of mydoc.txt named as mydoc.txt.gz and delete the original file.

How to decompress a gzip file in Linux?

The basic syntax of the gzip command for decompressing a file is as follows:

gzip -d filename.gz

This command decompresses the specified gzip file, leaving the original uncompressed file intact.

Keeping the Original File Using gzip Command in Linux

By default, gzip removes the original file after compression. To retain the original file, use the -k option:

gzip -k example.txt

This command compresses “example.txt” and keeps the original file intact.

Verbose Mode Using gzip Command in Linux

To obtain more details during compression or decompression, the -v option is employed:

gzip -v example.txt

Verbose mode provides information such as file sizes and progress during the compression or decompression process.

Force Compression Using gzip Command in Linux

In cases where the compressed file already exists, the -f option forcefully overwrites it:

gzip -f example.txt

This command compresses “example.txt” and overwrites any existing “example.txt.gz” file

Compressing Multiple Files Using gzip Command in Linux

Gzip can compress multiple files simultaneously by providing their names as arguments:

gzip file1.txt file2.txt file3.txt

This command compresses “file1.txt,” “file2.txt,” and “file3.txt” individually.

Recursive Compression with find Using gzip Command in Linux

To compress all files in a directory and its subdirectories, the find command can be combined with gzip:

find /path/to/directory -type f -exec gzip {} \;

This command recursively compresses all files in the specified directory.

Conclusion

In this article we discussed the gzip command which is a powerful tool on Linux for compressing and decompressing files using the DEFLATE algorithm. Its basic syntax allows for straightforward compression, with options like -k preserving the original file and -v providing detailed information. The -f option forcefully compresses, overwriting existing files, while -r facilitates recursive compression. Gzip’s versatility makes it a go-to tool for efficiently managing file sizes and navigating through directory structures.

Gzip Command in Linux – FAQs

What is gzip in Linux?

gzip is a file compression utility in Linux that reduces the size of files using the GNU zip compression algorithm. It compresses files to save disk space and reduce transmission time.

How to gzip a file?

To compress a file using gzip, use the following command:

gzip filename

This command compresses filename and replaces it with filename.gz.

How to make a gz file in Linux?

To create a .gz file in Linux, use the gzip command:

gzip filename

This will compress filename and create a filename.gz file.

How to zip a folder in Linux using gzip?

gzip cannot compress directories directly. Use the tar command combined with gzip to compress a folder:

tar -czvf foldername.tar.gz foldername/

This command creates a compressed archive foldername.tar.gz of the foldername directory.

How to use gzip to unzip files?

To decompress a .gz file using gzip, use the -d option:

gzip -d filename.gz

This command decompresses filename.gz and restores the original file filename.



Gzip Command in Linux - GeeksforGeeks (1)

GeeksforGeeks

Gzip Command in Linux - GeeksforGeeks (2)

Improve

Previous Article

How to Compress Files in Linux | Tar Command

Next Article

gunzip command in Linux with examples

Please Login to comment...

Gzip Command in Linux - GeeksforGeeks (2024)
Top Articles
The $400 billion man running America’s clean energy transition
Why a College Degree Isn't Necessary to Achieve Financial Freedom - Oddball Wealth
English Bulldog Puppies For Sale Under 1000 In Florida
Www.1Tamilmv.cafe
Jackerman Mothers Warmth Part 3
Login Page
9192464227
Apex Rank Leaderboard
When is streaming illegal? What you need to know about pirated content
Trade Chart Dave Richard
Mndot Road Closures
Shariraye Update
Nonuclub
Ts Lillydoll
Craigslist Farm And Garden Tallahassee Florida
iOS 18 Hadir, Tapi Mana Fitur AI Apple?
Craigslist Panama City Fl
50 Shades Of Grey Movie 123Movies
Exterior insulation details for a laminated timber gothic arch cabin - GreenBuildingAdvisor
Yard Goats Score
Timeforce Choctaw
Dallas Mavericks 110-120 Golden State Warriors: Thompson leads Warriors to Finals, summary score, stats, highlights | Game 5 Western Conference Finals
Winco Employee Handbook 2022
Purdue 247 Football
Governor Brown Signs Legislation Supporting California Legislative Women's Caucus Priorities
Shreveport City Warrants Lookup
Harrison County Wv Arrests This Week
The Collective - Upscale Downtown Milwaukee Hair Salon
Netspend Ssi Deposit Dates For 2022 November
Criglist Miami
3 Ways to Format a Computer - wikiHow
King Soopers Cashiers Check
Brenda Song Wikifeet
Wow Quest Encroaching Heat
Craigslist Albany Ny Garage Sales
Chris Provost Daughter Addie
Google Jobs Denver
Frank 26 Forum
Koninklijk Theater Tuschinski
The Holdovers Showtimes Near Regal Huebner Oaks
Craigslist Mexicali Cars And Trucks - By Owner
Metro Pcs Forest City Iowa
How Many Dogs Can You Have in Idaho | GetJerry.com
Ferguson Showroom West Chester Pa
Mississippi weather man flees studio during tornado - video
2013 Honda Odyssey Serpentine Belt Diagram
Port Huron Newspaper
Www.homedepot .Com
Dietary Extras Given Crossword Clue
Sml Wikia
Edict Of Force Poe
Craigs List Sarasota
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 5780

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.