unzip
The unzip
command in Linux is used to extract files and directories from ZIP archives. It's the counterpart to the zip
command and is widely used for decompressing files that have been compressed using the ZIP compression algorithm. Here are the key aspects and functionalities of the unzip
command:
Extracting Files: To extract all the contents of a ZIP archive, use
unzip
followed by the filename. For example,unzip file.zip
will extract all files and directories infile.zip
to the current directory.Listing Archive Contents: If you want to see the contents of a ZIP archive without extracting it, you can use
unzip -l file.zip
. This command lists the files included infile.zip
.Extracting Specific Files: To extract specific files from a ZIP archive, specify the file names after the archive name. For instance,
unzip archive.zip file1.txt file2.txt
will extract onlyfile1.txt
andfile2.txt
fromarchive.zip
.Extracting to a Different Directory: If you want to extract files to a different directory rather than the current one, use the
-d
option. For example,unzip file.zip -d /path/to/directory
will extract the contents offile.zip
into/path/to/directory
.Overwriting Existing Files: When extracting, if there are existing files with the same names,
unzip
will prompt for action (overwrite, skip, etc.). You can automate this process using options like-o
to overwrite files without prompting or-n
to never overwrite existing files.Preserving File Timestamps and Permissions:
unzip
typically preserves the original timestamps and permissions of the files in the ZIP archive.Handling Encrypted Archives: If a ZIP archive is password-protected,
unzip
will prompt for the password. You can also specify the password with the-P
option, but this is not secure as it may be visible in the command history or process list.Testing Archive Integrity: To check the integrity of a ZIP archive without extracting it, use
unzip -t file.zip
. This command tests whether the archive is corrupted.Verbose Output: Using the
-v
option withunzip
provides more verbose output, showing additional details about the extraction process.
Last updated