The basic command to unzip a file in Linux

To unzip a file in Linux, use the unzip command followed by the filename. Open your terminal, navigate to the folder where your .zip file is located, and type:

unzip filename.zip

This extracts all files from the archive into the current directory. The original .zip file remains unchanged — unzip does not delete it after extraction. Every file and folder structure inside the archive is recreated exactly as it was packaged.

If you want the extracted files to go into a specific folder instead, add the -d flag followed by the destination path:

unzip filename.zip -d /path/to/destination

The destination folder does not need to exist beforehand — unzip will create it if necessary. This is useful when you are organizing downloads or extracting archives into project directories.

Key Takeaways

  • The command unzip filename.zip extracts all files from a .zip archive into your current directory without deleting the original file.
  • Use unzip filename.zip -d /path/to/folder to extract files into a specific folder instead of the current one.
  • The unzip -l filename.zip command shows you what is inside a .zip file before you extract it, including file sizes and dates.
  • If a file already exists with the same name, unzip will ask before overwriting it unless you use the -o flag to overwrite automatically.
  • Use unzip -j filename.zip to extract files without preserving the folder structure inside the archive.

Preview what is inside a .zip file before extracting

Before extracting, you may want to see what files are in the archive. Use the -l flag to list the contents without extracting anything:

unzip -l filename.zip

This shows the filename, size in bytes, date, and time for each file inside. It is useful when you are not sure what the archive contains or how much disk space you need before extraction. The output also shows the total number of files and the compressed versus uncompressed size at the bottom.

If the list is long and scrolls past your screen, pipe it to a pager to read it one screen at a time:

unzip -l filename.zip | less

Extract only specific files from a .zip archive

If you only need certain files from a large archive, you can extract them by name instead of extracting everything. Type the unzip command followed by the specific filenames:

unzip filename.zip file1.txt file2.txt

You can also use wildcards to extract files matching a pattern. For example, to extract only .txt files:

unzip filename.zip "*.txt"

Note the quotes around the wildcard — they prevent your shell from interpreting the asterisk before unzip sees it. Without quotes, the shell expands the wildcard to files on your disk, not files inside the archive, which causes an error.

This selective extraction saves time and disk space when you are working with large archives that contain many files you do not need.

Handle conflicts when files already exist

If a file with the same name already exists in your destination folder, unzip will pause and ask whether to overwrite, skip, or rename it. You can control this behavior with flags to avoid interruption.

Use -o to overwrite all existing files without asking:

unzip -o filename.zip

Use -n to skip any files that already exist:

unzip -n filename.zip

Use -u to overwrite only if the file in the archive is newer than the one on disk:

unzip -u filename.zip

The -u flag is particularly useful when you are updating a project — it extracts only files that have changed since the last extraction, leaving your modifications to other files untouched.

Extract files without creating a parent folder

Some .zip files are structured so that all contents sit inside a single parent folder. When you extract, that folder is created automatically. If you want to extract the contents directly into your current directory without the parent folder, use the -j flag:

unzip -j filename.zip

This is called "junk paths" mode. It extracts all files but ignores the folder structure inside the archive, placing every file directly in your destination directory. Be careful with this option if the archive contains files with the same name in different folders — they will overwrite each other.

You can combine -j with -d to extract flattened files into a specific folder:

unzip -j filename.zip -d /path/to/destination

Unzip files with a password

If a .zip file is password-protected, unzip will prompt you to enter the password when you run the command:

unzip filename.zip

Type the password when prompted. For security, the password does not appear on screen as you type, and no asterisks or dots show your progress.

If you want to provide the password in the command itself (not recommended for sensitive files), use the -P flag:

unzip -P password filename.zip

This method is less secure because the password appears in your command history and may be visible to other users on the system. For sensitive archives, always let unzip prompt you for the password instead.

Frequently Asked Questions

What if the unzip command is not found?

The unzip tool is not installed by default on all Linux systems. On Ubuntu or Debian, install it with sudo apt install unzip. On Fedora or Red Hat, use sudo dnf install unzip. On Alpine, use apk add unzip.

Can I unzip multiple files at once?

Yes. Type unzip "*.zip" to extract all .zip files in the current directory. Each archive extracts into the current directory or into its own folder depending on how it was created. You can combine this with -d to extract all archives into a specific destination folder.

How do I see all the unzip command options?

Type man unzip to open the manual page, which lists all flags and options with detailed explanations. Press q to exit the manual. You can also type unzip -h for a shorter summary of the most common options.

What is the difference between unzip and tar?

unzip handles .zip files, which are common on Windows and the web. tar handles .tar, .tar.gz, and .tar.bz2 files, which are more common in Linux and Unix systems. They are separate tools designed for different archive formats.

Can I test a .zip file before extracting it?

Yes. Use unzip -t filename.zip to test the archive for errors without extracting anything. This checks whether the file is corrupted and whether you have the correct password for encrypted archives.