How To Zip A File In Linux Terminal

Linux, one of the most versatile operating systems, offers a plethora of functionalities through its powerful command line interface (CLI), also known as the terminal. One such functionality is file compression or ‘zipping’. Compressing files can be extremely beneficial, particularly when you need to send multiple files over email or save storage space.

In this tutorial, we will learn how to zip a file in Linux using Terminal. The most common tools used for this purpose are ‘zip’ and ‘gzip’. Here is a step-by-step guide to help you zip files using these tools.

Using the ‘zip’ Command

To start, let’s use the zip command. You can install it with the following command if it’s not already installed:

sudo apt-get install zip

Once installed, you can zip a file using the following syntax:

zip archive_name file_name

This command will create a new zipped file named containing the file file_name.

If you want to zip a directory instead of a single file, simply use the -r (recursive) option:

zip -r archive_name directory_name

Using the ‘gzip’ Command

Another tool that you can use to zip files in Linux is gzip. Just like ‘zip’, you can install it with:

sudo apt-get install gzip

The syntax for zipping a file with ‘gzip’ is a bit different:

gzip file_name

This command will replace the original file with a new compressed file having the extension ‘.gz’. To keep the original file intact, use the -k option:

gzip -k file_name

‘gzip’ can only compress individual files. If you need to zip a directory, you can use the tar command in combination with ‘gzip’ as follows:

tar -czvf archive_name.tar.gz directory_name

This command will create a ‘.tar.gz’ archive file from the specified directory.


As you can see, zipping a file or a directory in Linux terminal is not a daunting task. It simply requires a few commands and knowledge about the options provided by tools like ‘zip’ and ‘gzip’. Whether you need to save storage space or send multiple files in an email, knowing how to compress files is a critical skill for any Linux user.