ZIP command in Linux

Last Updated : 13 Feb, 2026

The zip command compresses one or more files or directories into a single .zip archive file. This helps save disk space, keeps data well organized, and makes it easy to share or back up files. It is widely used for compressing large files before sending them via email or uploading them to cloud storage.

Below are some common reasons people use the zip command:

  • To reduce file size and save storage.
  • To combine multiple files/folders into one for easier sharing.
  • To protect files with passwords (using options).
  • Works across platforms-ZIP files open easily on Windows, Linux, and macOS.

Example: Compress Multiple Files

To compresses multiple files into a single ZIP archive. 

Command:

zip myfiles.zip file1 file2 file3
  • zip: Command used to create a ZIP archive
  • myfiles.zip : Name of the output ZIP file (archive to be created)
  • file1 file2 file3: List of files to compress and include inside the archive

Output:

zip
file compression using zip

Syntax

zip [options] archive_name.zip file1 file2 folder/
  • zip: Command used to create a compressed archive
  • archive_name.zip: Name of the ZIP file to be created
  • file1 file2 folder/: Files or directories to be compressed
  • [options]: Optional flags to modify the behavior of the command

Commonly Used Options

1. -d: Delete a File from Archive

The -d option is used to remove a specific file from an existing ZIP archive without extracting the archive.

Syntax:

zip -d [file_name.zip] [files_name]

Example: Suppose we have zip file "name = myfile.zip" and have eight files in it "name = hello1.c, hello2.c, hello3.c, hello4.c, hello5.c, hello6.c, hello7.c, hello8.c ". We have to delete hello7.c.

Command:

zip -d myfile.zip hello7.c
  • -d: Deletes file from archive
  • myfile.zip : Existing ZIP file
  • hello7.c: File to delete.

Output:

delete a file from zip file
delete a file from zip file

Note: Use `sudo` if you encounter permission errors.

2. -u: Update Archive with New Files

The -u option updates an existing ZIP archive by adding new files or replacing files if they are modified. It is useful when working on projects that frequently change.

Syntax:

zip -u [archived_file_name.zip] [files_name]

Example: Suppose we have zip file "name= myfile.zip" and we have to add a new file "name = hello9.c" in it.

Command:

zip -u myfile.zip hello9.c
  • -u : Updates archive
  • myfile.zip : Existing ZIP file
  • hello9.c : File to add or update

Output:

add a file in zip file
add a file in zip file
  • we have used `vi` to see that our file is added successfully.

3. -m: Move Files into Archive

The -m option compresses the specified files and then deletes them from their original location. It works like “cut and zip,” which is useful when files need to be archived and removed to save space.

Syntax:

zip -m [archive_file_name.zip] [files_name]

Example: Suppose we have zip file "name = myfile.zip" and we have to move files "name = hello1.c, hello2.c, hello3.c, hello4.c, hello5.c, hello6.c, hello8.c, hello9.c " Present in current directory to zip file.

Command:

zip -m myfile.zip *.c
  • -m : Move files (zip + delete original)
  • myfile.zip : Target ZIP file
  • *.c: All C files in directory

Output:

moved files inside zip file
moved files inside zip file
  • we have used `ls` to see that our files are moved successfully.

4. -r: Recursively Zip a Directory

The -r option compresses an entire directory including its subdirectories and files. It is commonly used to back up folders or project directories.

Syntax:

zip -r [file_name.zip] [directory_name]

Example: Suppose we have zip file "name= myfile.zip" and we have to move files "name = hello1.c, hello2.c, hello3.c, hello4.c, hello5.c, hello6.c, hello7.c, hello8.c " present in directory "name= jkj_gfg" to zip file recursively. 

Command:

zip -r myfile.zip jkj_gfg/ 
  • -r : Recursive compression
  • myfile.zip: Output ZIP archive
  • jkj_gfg/ : Folder to compress

Output:

copy file recursively form a directory to a zip file
copy file recursively form a directory to a zip file
  • To check files inside "myfile.zip" we can type "vi myfile.zip".

5. -x: Exclude Files from Archive

The -x option excludes specific files or patterns while creating a ZIP archive. It is useful when you want to compress everything except certain files.

Syntax:

zip -r [archive_name.zip] [directory ] -x [file_name]

Example: Suppose we have zip file "name= myfile.zip" and we have to move files "name = hello1.c, hello2.c, hello3.c, hello4.c, hello5.c, hello6.c, hello7.c, hello8.c " present in directory "name= jkj_gfg" to zip file recursively. 

Command:

zip -r myfile.zip . -x  a.txt
  • -x: Excludes files from archive
  • .: Current directory
  • a.txt: File to exclude

Output:

file copied recursively except one file we mentioned
file copied recursively except one file we mentioned.
  • To check files inside "myfile.zip" we can type "vi myfile.zip".

6. -v: Verbose Mode

The -v option enables verbose mode, which displays detailed information during compression such as file names and compression statistics. It helps in monitoring the zip process.

Syntax:

zip -v [archive_name.zip] [file_name]

Example: Detailed compression progress and file information are displayed in the terminal.

Command:

zip -v myfile.zip b.txt
  • -v : Enables verbose output
  • myfile.zip: Output archive file
  • b.txt: Files to compress

Output:

checking information about all files inside zip
checking information about all files inside zip

unzip Command

The unzip command is used to extract files from a ZIP archive. By default, it extracts the contents into the current working directory.

Syntax:

unzip [file_name.zip]

Example: Suppose we have a zip file "name = jayesh_gfg.zip" and we have three text files inside it "name = a.txt, b.txt and c.txt". we have to unzip it in the current directory.

Command:

 unzip jayesh_gfg.zip
  • unzip : Command to extract files
  • jayesh_gfg.zip : ZIP archive to extract

Output:

Here, we used `ls` command to display all the files that has be unzipped from the zipped file.

Real-World Use Cases of zip Command

Below are some practical situations where the zip command is commonly used.

1. File Backup and Storage

The zip command is widely used to back up project files, assignments, documents, or important data.

zip -r backup.zip mydata/

2. Sharing Multiple Files Together

Instead of sending many files one by one, users compress them into a single archive.

zip project.zip *.c
  • Makes file transfer easier and faster.

3. Saving Disk Space

Large files can be compressed to reduce size and save storage.

zip logs.zip /var/log

4. Cross-Platform File Sharing

ZIP files are supported on Windows, Linux, and macOS, making them ideal for sharing files between systems.

Comment

Explore