Using ZIP’ed directories is often necessary when transferring files from one computer to another, or when restoring backups.
This guide shows how to unzip directories using the terminal on your Ubuntu server, and covers various options for handling file conflicts.
Pre-Requisites
-
- An Ubuntu Server
- Access to the terminal
- unzip installed
Unzipping a Directory
- Open the terminal on your Ubuntu server.
- Navigate to the directory containing the zip file you wish to extract.
- Use the
cd
command to change directories. E.g.,cd /path/to/directory
.
- Run the following command to unzip the archive.
unzip archive_name.zip
Handling File Conflicts
When unzipping an archive, you might encounter situations where files within the zip archive have the same names as files in the destination directory. The unzip
command provides several options to handle such conflicts:
- Overwriting existing files without prompting:
unzip -o archive_name.zip
- Renaming files automatically to avoid overwriting:
unzip -B archive_name.zip
- Prompting for action on each conflict:
unzip -n archive_name.zip
Advanced Unzipping Options
- Extracting to a different directory:
unzip archive_name.zip -d /path/to/destination
- Listing the contents of a zip file without extracting:
unzip -l archive_name.zip
- Excluding specific files or patterns:
unzip archive_name.zip -x filename_to_exclude.ext
- Extracting only specific files or patterns:
unzip archive_name.zip filename_to_extract.ext
- Overwriting newer files:
unzip -o -DD archive_name.zip