You can quickly view the contents of a ZIP file in Linux without extracting it first using the `unzip` command. This one-liner simply lists the files inside, saving time when you only need to inspect rather than unpack. Just run `unzip -l file.zip` in your terminal, and you’ll see a clean list of everything inside. No extra setup is required—it works on most Linux distributions, including Ubuntu, Fedora, and Arch.
What You'll Need
- A Linux terminal (built into all modern desktop environments and most servers).
- A ZIP file you want to inspect—it can be anywhere on your filesystem.
- No additional software is needed; `unzip` comes preinstalled on most systems.
Step-by-Step
- Open a terminal. On desktop Linux, press Ctrl+Alt+T or find it in your applications menu. On Linux servers or lightweight environments, you’ll use the same key combination or type `gnome-terminal` (GNOME) or `konsole` (KDE) to launch one.
-
Navigate to the directory where your ZIP file is stored. Use the
cdcommand followed by the path, for example:cd ~/Downloads. For hidden files, include the.prefix:cd ~/.local/share/. -
Type the command to list the ZIP file’s contents without extracting it:
unzip -l file.zip. Replacefile.zipwith your actual ZIP filename. If you omit the filename and just typeunzip -l, it will search the current directory for ZIP files. -
Press Enter. The output will display each file inside the ZIP, including subdirectories (marked with a trailing slash). Example output:
Archive: archive.zip 1 file.txt 2 subfolder/ 3 subfolder/image.png
If That Did Not Work
If you get an error likeunzip: cannot open file.zip: No such file or directory, double-check:
- The ZIP file exists in the current directory.
- You used the correct filename (case-sensitive on some systems).
- The file has the right extension (.zip).
If the command isn’t recognized, install `unzip` manually:
sudo apt update && sudo apt install unzip (Debian/Ubuntu)
or
sudo dnf install unzip (Fedora)
or
sudo pacman -S unzip (Arch Linux).
Common Mistakes
- **Typo in the filename**: Use `unzip -l file.zip` (note the space after -l). No spaces around the dash. - **Forgetting to run as a user with permissions**: If the ZIP is in a restricted directory, ensure you’re in the correct folder before running the command. - **Using -l incorrectly**: The-l flag lists contents only. To extract, use unzip file.zip or unzip -d output_dir file.zip.
Tips
- **View without extracting**: Always use-l to preview. Extracting first wastes space and time.
- **Filter hidden files**: Use wildcards to list only files with a specific extension, e.g.,
unzip -l *txt.zip.
- **Compare ZIPs**: To list contents of multiple ZIPs in one command, chain them:
unzip -l file1.zip file2.zip.
- **Quick grep**: Use unzip -l | grep "filename" to search for a specific filename in the list.
- **Use `--installer` or `--installer-options`**: If you need to install files from the ZIP (e.g., software packages), use:
unzip -i file.zip for interactive install, or
unzip -i -o file.zip to override existing files.
Troubleshooting
- **Permission denied**: Run the command with sudo only if the ZIP is system-wide (e.g., /usr/share/). For personal files, ensure you’re in the right directory. - **Corrupted ZIP**: If the file isn’t opening at all, verify its checksum or extract it manually first:7z l file.zip (uses `p7zip`; install with sudo apt install p7zip-full).
- **No output**: Confirm the ZIP isn’t empty. Check its size with ls -lh file.zip or inspect it in a file manager.
Frequently Asked Questions
What if my terminal doesn’t recognize `unzip`?
Install it with your package manager:sudo apt install unzip (Debian/Ubuntu)
or
sudo dnf install unzip (Fedora).
It’s available on Arch Linux by default.
Can I list ZIP contents in a specific directory?
Yes, navigate to that directory first, then rununzip -l file.zip. To avoid moving files, use absolute paths:
unzip -l /full/path/to/file.zip.
How do I extract multiple ZIPs at once?
Use a loop (Bash) or script. Example:
for zip in *.zip; do
echo "Extracting $zip..."
unzip "$zip"
done
What if the ZIP has password protection?
You must extract it first or use a tool likezipfile (Python) or 7z:
7z x file.zip -ooutput_dir.
Will this work on macOS or Windows?
No. `unzip` is a Linux/Unix tool. On macOS, usezipinfo file.zip (included with macOS). On Windows, use the built-in Expand-Archive (PowerShell) or GUI.
How do I list ZIP contents in a terminal without extracting?
Useunzip -l file.zip (Linux) or zipinfo file.zip (macOS). Avoid extracting unless necessary.