Linux unzip Command
The Linux unzip command is used to extract compressed files in .zip format.
The unzip tool can extract .zip files containing multiple files and directories, and is widely used to handle cross-platform compressed files.
Syntax
unzip [options] file.zip
file.zip: the file to be extracted.zipfiles.
options parameters:
-d: put the extracted files into the specified directory.-l: list the.zipcontents of the file, without extracting.-v: display detailed information, including the.zipfile's structure, compression ratio, and other information.-t: test the.zipfile's integrity, without extracting.-n: do not overwrite existing files when extracting.-o: overwrite existing files when extracting, without prompting.-x: exclude the specified files or directories when extracting.-j: do not preserve the directory structure when extracting; extract all files into the current directory.
Example
Extract a .zip file
unzip archive.zip
This command extracts the contents of archive.zip into the current directory.
** Extract to a specified directory**
unzip archive.zip -d /path/to/directory
This command extracts the contents of archive.zip into the specified /path/to/directory directory.
** List the contents of a .zip file**
unzip -l archive.zip
This command lists all files and directories in archive.zip without actually extracting them.
** Test the integrity of a .zip file**
unzip -t archive.zip
This command tests the integrity of the archive.zip file to ensure it is not corrupted.
** Exclude specific files when extracting**
unzip archive.zip -x "*.log"
This command extracts archive.zip but excludes all .log files.
** Do not overwrite existing files when extracting**
unzip -n archive.zip
This command extracts the files in archive.zip, but if a file with the same name already exists in the target directory, that file is skipped and not overwritten.
** Extract files and overwrite existing files**
unzip -o archive.zip
This command overwrites existing files with the same name in the target directory when extracting archive.zip, without prompting the user.
** Do not preserve the directory structure when extracting**
unzip -j archive.zip
This command extracts all files from archive.zip into the current directory without preserving the original directory structure.
Notes
unzipBy default, the original directory structure is preserved when extracting files. If you do not need to preserve the directory structure, you can use-joption.unzipcan be used via-xthe option to exclude certain files or directories, which is useful for selectively extracting specific files.
Linux Command Reference