Zip/Unzip on Linux: Reference and Examples
Last updated:Table of Contents
- Zip single file
- Zip directory
- Unzip single file
- Unzip to new directory
- Zip with password
- Add password
- Using multiple modifiers
- Unzip, overwrite existing files
Zip single file
$ zip large-file.zip large-file.txt
Zip directory
$ zip -r large-dir.zip large-dir/
Unzip single file
$ unzip large-file.zip
Unzip to new directory
By default, stuff is extracted into the current directory, which can cause a mess if you archive has many files.
Use -d <name-of-new-directory>
to extract files to a new directory.
$ unzip -d someDirectory myarchive.zip
Zip with password
You'll be prompted for a password to protect your archive (you won't see it typed to the terminal however)
$ zip -e large-file.zip large-file.txt
Add password
See above: Zip with password
Using multiple modifiers
For example, encrypt and zip directory
$ zip -re large-dir.zip large-dir/
Unzip, overwrite existing files
Example unzip archive
into the current directory and overwrite existing files if they exist:
$ unzip -o archive.zip