In the world of Linux, there are many powerful tools available that can help you manage your files more efficiently. One of these tools is the
gzip command, which is used to compress and decompress files. In this beginner’s guide, we’ll take a closer look at gzip command in Linux and how to use it.
What is the Gzip Command in Linux?
gzip command is a tool that is used to compress and decompress files in Linux. The name “gzip” stands for “GNU zip”, as it is a part of the GNU project. The command works by taking a file and compressing it into a smaller size, which makes it easier to store and transfer. When you need to use the file again, you can decompress it using the
gzip command, which restores it to its original size and format.
How to Use the Gzip Command in Linux?
gzip command in Linux is relatively easy.
To use the
gzip command, you need to open a terminal window in Linux. To do this, press
Ctrl + Alt + T on your keyboard or open the terminal from the applications menu.
Once you have opened the terminal, navigate to the directory where the file you want to compress or decompress is located. You can use the
cd command to change the directory.
Here are the basic operation we’ll perform here.
Compressing a File Using Gzip Command
To compress a file using
gzip, simply type the following command in the terminal:
For example, if you want to compress a file named
myfile.txt, you would type:
gzip command will compress the file and add the
.gz extension to its name.
Decompressing a File Using Gzip Command
To decompress a file that has been compressed with
gzip, type the following command in the terminal:
gzip -d <filename>
For example, if you want to decompress a file named
myfile.txt.gz, you would type:
gzip -d myfile.txt.gz
-d option stands for “decompress”.
Creating a Compressed File with a Custom Name
You can also create a compressed file with a custom name using the
-c option. For example, if you want to compress a file named
myfile.txt and create a compressed file named
compressedfile.gz, you would type:
gzip -c myfile.txt > compressedfile.gz
Viewing the Contents of a Compressed File
To view the contents of a compressed file without decompressing it, use the
zcat command followed by the name of the compressed file. For example, to view the contents of a file called
Listing the Contents of a Compressed File
To list the contents of a compressed file, use the
gzip command followed by the
-l option and the name of the compressed file. For example, to list the contents of a file called
gzip -l compressedfile.gz
gzip command is a powerful tool that can help you manage your files more efficiently in Linux. Whether you need to compress large files to save disk space or transfer them more easily, or decompress them to use them again, the
gzip command can make your life easier. With this beginner