Linux – zip and unzip Command

ZIP Command

The zip command is used to compress files and directories into a .zip archive. This reduces the file size and makes it easier to transfer or store multiple files together in a single archive.

Initial Example

Using zip to compress a file called example.txt into an archive called archive.zip:

UNIX

Tutorials dojo strip

Examples

1. Compress Multiple Files

To compress multiple files into a single archive, specify their names followed by the archive name:

UNIX

2. Compress a Directory

To compress an entire directory and its contents, use the -r (recursive) option:

UNIX

3. Add Files to an Existing Archive

To add files to an existing .zip archive, use the same command with the additional files:

UNIX

4. Exclude Specific Files

To exclude specific files from the archive, use the -x option followed by the pattern to exclude:

UNIX

5. Password-Protect an Archive

To password-protect a .zip archive, use the -e (encrypt) option:

UNIX

UNZIP Command

The unzip command is used to extract files and directories from a .zip archive. This allows you to access the compressed files and use them as needed.

Initial Example

Using unzip to extract the contents of an archive called archive.zip:

UNIX

Examples

1. Extract to a Specific Directory

To extract the contents of a .zip archive to a specific directory, use the -d option followed by the directory path:

UNIX

2. List Contents of an Archive

To list the contents of a .zip archive without extracting them, use the -l option:

UNIX

3. Extract Specific Files

To extract specific files from an archive, specify the file names after the archive name:

UNIX

4. Overwrite Existing Files Without Prompting

To overwrite existing files without prompting for confirmation, use the -o option:

UNIX

5. Password-Protected Archives

To extract files from a password-protected archive, you’ll be prompted to enter the password:

UNIX

Linux Playground

Tutorials dojo strip
Scroll to Top