Zip and Unzip commands in Linux/Unix

Filed Under: UNIX/Linux

In this guide, we will focus on zip and unzip commands in Linux. zip command is a utility commonly used to compress files, while unzip command is used for uncompressing or unzipping files. Let’s have a look at each of these commands in detail.

Compressing files using the zip command

To create a compressed file with a .zip file extension, use the zip syntax as shown

zip {options} zipfile file_name

How to compress files with zip command

To compress a single file to a zip file without any arguments use the syntax below

$ zip zipfile file_name

Let’s create a file file1.doc using touch command

$ touch file1.doc

Next, we are going to zip or compress it to

$ zip file1.doc


Zip A Single File

To verify the creation of the zipped file use the ls command as shown

ls -l


Display Zipped File

Similarly, you can zip multiple files into one zipped file. Suppose we have 4 files as shown


To zip the files

$ zip file1.doc file2.doc file3.doc file4.doc


Zip Multiple Files

Once again, if you wish to verify the results, use the ls command as shown below


Display Zipped Files

Adding a new file to a pre-existing compressed file

Let’s assume you have created 2 more files; file5.doc and file6.doc and you want to include it to the zipped file.

Use the -u argument as shown below

$ zip file5.doc file6.doc


Add Files To A Zipped File

Deleting a file from a compressed file

To delete a file from an archive or a compressed file, use the -d flag as shown

$ zip -u compressed_file file_name

Suppose you want to delete file2.doc and file3.doc from the compressed file. The command will be

$ zip -d file2.doc file3.doc


Deleting Files From A Compressed File

Deleting original files after arching or compressing

To delete files after compressing , use the -m option as shown

$ zip -m archive file_name

In our example where we have the following files,


The command shall be

$ zip -m *.doc


$ zip -m file1.doc file2.doc file3.doc file4.doc


Delete Files After Zipping

Zipping a directory recursively

If you wish to zip a directory recursively, use the -r option. This command will zip all the files in the directory and save on space.

The syntax for this will be

$ zip –r directory_name

suppose we have a directory called data the following files


To zip it into a zip file called the command will be

$ zip -r data


Zip Directories Recursively

Exclude a file from being zipped or compressed

To exclude a file from being compressed use the -x option as shown

$zip –x file_to_be_excluded

In the previous example, to exclude file2.doc from getting compressed, run

$ zip -x file1.doc

Getting help with zip commands

If you are stuck and want to know more about the usage of zip command run

$ zip --help


Zip Help

Additionally, you can visit the command’s man pages as shown

$ man zip


Man Zip

Unzip command

Unzip command is the converse of zip command. It is used for decompressing or unzipping compressed files and comes with several options. The syntax for unzipping files is

$ unzip {option}

Checking the contents of a zipped directory before unzipping

If you wish to display the contents of an archive before unzipping, use the -l option as shown

$ unzip -l

For instance

$ unzip -l


List Files Before Unzipping

Unzipping files with verbose output

To unzip a zipped file/directory with verbose output, use the -v option as shown

$ unzip -v


Unzip display verbose output

Unzipping files to a specific directory

If you want to unzip an archive to a specified directory , use the -d option as shown

$ unzip -d directory_name

To unzip the zip files into a directory called james, execute

$ unzip -d james


Unzip To A Different Directory

Checking for errors in an archive

If you wish to check for any errors in the archive before uncompressing, use the -t flag as shown

$ unzip -t 


Testing For Errors In Archive

Getting help with unzip commands

If you are stuck and want to know more about the usage of unzip command run

$ unzip --help


Unzip Help

Additionally, you can visit the command’s man pages as shown

$ man unzip


Man Unzip

That’s all we had for today. Your feedback is highly welcome.


  1. jack miller says:

    RAR file is used to store other files inside, it is a compressed folder if you want to open RAR files then you have to UNRAR it you need to download it from the internet using a free tool.

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content