How to Extract a Zip File in Ubuntu via Command Line

The Archive Extraction Vector

When downloading software packages, web server configurations, or project backups on an Ubuntu Linux system, the files are almost always delivered in a compressed ZIP archive. Because headless servers do not possess graphical file managers, you cannot simply double-click the archive to extract its contents. You must rely on the command-line interface to accurately decompress the files into the correct directory without overwriting existing data.

How to Extract a Zip File

The standard tool for decompressing these archives in Ubuntu is the unzip command. If it is not already installed on your system, you can obtain it by running sudo apt install unzip.

1. Open your terminal application or connect to your server via SSH.
2. Navigate to the directory containing your compressed archive.
3. To extract the entire contents of the ZIP file directly into your current working directory, execute the basic command:

unzip filename.zip

4. This approach is often messy, as it spills the extracted files directly into your current folder. To force the extraction into a completely new, dedicated directory, use the -d (destination) flag:

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

5. If you only want to view the contents of the archive without actually extracting anything (for example, to verify you downloaded the correct file), use the -l (list) flag:

unzip -l filename.zip

The terminal will instantly output a clean list of all the files packed inside the archive, along with their sizes, allowing you to confirm the contents before committing to an extraction.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.