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 the zipped file is located, and type unzip filename.zip. The command extracts all files and folders from the archive into your current directory.
If the zipped file is in a different folder, include the path: unzip /path/to/filename.zip. Linux will show you each file as it extracts, then return you to the command prompt when finished.
Most Linux systems come with unzip already installed. If you get a "command not found" error, your system may need it installed first — you can add it through your package manager (apt, yum, or dnf, depending on your distribution).
Key Takeaways
- The command unzip filename.zip extracts all contents of a zipped file into your current folder.
- Use unzip -l filename.zip to see what is inside a zipped file without extracting it.
- Extract to a specific folder with unzip filename.zip -d /path/to/folder to keep your files organized.
- Use unzip -o filename.zip to overwrite existing files without being asked, or unzip -n filename.zip to skip files that already exist.
Viewing what is inside a zipped file first
Before extracting, you may want to see what files are in the archive. Use unzip -l filename.zip to list the contents without extracting anything. This shows you the filenames, sizes, and folder structure so you know what you are about to unzip.
If the archive is large or you only want to see certain files, pipe the output to grep: unzip -l filename.zip | grep searchterm. This filters the list to show only files matching your search term.
Extracting to a specific folder
By default, unzip puts files in your current directory. To extract into a different folder, use the -d flag: unzip filename.zip -d /path/to/destination. If the destination folder does not exist, unzip will create it for you.
This is useful when you want to keep extracted files separate from the original archive, or when you are extracting multiple zipped files and want each one in its own folder. For example, unzip archive.zip -d ~/Downloads/extracted puts everything into an "extracted" folder inside your Downloads directory.
Handling files that already exist
If a file with the same name already exists in the destination folder, unzip will ask whether to overwrite it, skip it, or rename it. You can control this behavior with flags instead of answering each prompt.
Use unzip -o filename.zip to overwrite all existing files without asking. Use unzip -n filename.zip to skip any file that already exists and extract only new ones. Use unzip -u filename.zip to update existing files only if the zipped version is newer.
Extracting a single file from an archive
You do not have to extract everything. To pull out just one file, type unzip filename.zip path/to/specific/file. Replace "path/to/specific/file" with the exact name and location shown when you listed the archive contents.
You can extract multiple specific files by listing them: unzip filename.zip file1.txt file2.txt folder/file3.txt. This is faster than extracting the whole archive when you only need a few items.
Testing a zipped file for errors
Before extracting an important archive, you can test whether it is corrupted. Use unzip -t filename.zip to check every file in the archive without extracting it. Linux will report if any files are damaged or incomplete.
This catches problems early, especially with large files downloaded from the internet where corruption during transfer is possible. If the test finds errors, you may need to re-read the file or contact whoever sent it to you.
Working with other compressed formats
Linux also handles other compressed file types. For .tar.gz files, use tar -xzf filename.tar.gz. For .tar.bz2 files, use tar -xjf filename.tar.bz2. For .7z files, use 7z x filename.7z (you may need to install the 7z package first).
Each format has its own command, but the principle is the same: you are extracting compressed files into readable form. If you are unsure which command to use, check the file extension — it tells you the compression method used.
Frequently Asked Questions
What if I get a "command not found" error when I type unzip?
Your system does not have unzip installed. On Ubuntu or Debian, type sudo apt install unzip. On Fedora or CentOS, type sudo dnf install unzip. You will need administrator access (sudo) to install it. Once installed, the unzip command will work normally.
Can I unzip a file that is password-protected?
Yes. Type unzip -P password filename.zip, replacing "password" with the actual password. Linux will extract the files without prompting you. If you do not include the password flag, unzip will ask you to enter it before extracting.
How do I unzip multiple files at once?
Use a wildcard: unzip '*.zip'. The single quotes tell Linux to treat the asterisk as a wildcard that matches all .zip files in the current folder. Each archive extracts into your current directory, so use the -d flag if you want each one in a separate folder.
What does the -v flag do?
The -v flag shows more details while unzipping — file sizes, compression ratios, and timestamps. Type unzip -v filename.zip to see this extra information as files extract. It is useful for understanding how much space the archive saved.
Can I see the progress of a large unzip operation?
The standard unzip command shows each filename as it extracts, which gives you a sense of progress. For a simpler view, use unzip -q filename.zip to extract quietly with no output, or use unzip filename.zip | tail to see only the last few files being extracted.