ZIP command in Linux (original) (raw)

Last Updated : 11 Jun, 2026

The zip command is a command-line utility used to compress one or more files or directories into a single .zip archive file. This utility helps optimize disk space, keeps data well organized, and makes it easy to transfer or back up files across multi-platform networks.

Syntax of zip Command

The standard syntax of the zip command in Linux is structured as follows:

zip [options] archive_name.zip file1 file2 folder/

Basic Compression Examples

To compress multiple individual files into a single ZIP archive, execute the following command:

zip myfiles.zip file1 file2 file3

zip

File compression output using the default zip command

Commonly Used Options

The zip command offers several operational flags to manage files inside archives directly:

1. -d: Delete a File from Archive

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

zip -d myfile.zip hello7.c

57

Executing a delete action inside an archive using the -d option

**Note: If you encounter permission errors when modifying protected archive files, prepend the command with sudo.

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. This is highly useful for progressive project archiving.

zip -u myfile.zip hello9.c

58

Adding or updating archive records using the -u option

3. -m: Move Files into Archive

The -m option compresses specified target files and then deletes them from their original location on disk. It acts as a "cut and zip" operation.

zip -m myfile.zip *.c

59

Using the -m option to automatically clear local storage after packaging

4. -r: Recursively Zip a Directory

The -r option traverses and compresses an entire directory, including all nested subdirectories and files.

zip -r myfile.zip jkj_gfg/

60

Recursively packaging directory structures using the -r option

5. -x: Exclude Files from Archive

The -x option allows you to exclude specific files or extension patterns from being compressed during archive creation.

zip -r myfile.zip . -x a.txt

62

Filtering specific records out of compression using the -x option

6. -v: Verbose Mode

The -v option runs the command in verbose mode, outputting progress bars, diagnostic information, and individual compression ratios.

zip -v myfile.zip b.txt

63

Executing verbose commands to check diagnostic details

Extraction with unzip Command

The unzip command is used to extract contents from an archive into the target environment.

unzip jayesh_gfg.zip

56

Extracting a zip archive back into raw files using the unzip command

You can run the ls command immediately afterward to verify that the extracted files now exist in the target working directory.