Linux unzip command

Linux 命令大全Linux Command Collection

The Linux unzip command is used to extract.zipcompressed 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.zipextracted.

The options parameter:

  • -d <directory>: Place the extracted files in the specified directory.
  • -l: List.zipthe contents of the file, but do not extract.
  • -v: Display detailed information, including.zipthe file structure and compression ratio, etc.
  • -t: Test.zipthe integrity of the file, but do not extract.
  • -n: Do not overwrite existing files when extracting.
  • -o: Overwrite existing files when extracting without prompting.
  • -x <pattern>: Exclude specified files or directories when extracting.
  • -j: Do not preserve the directory structure when extracting; extract all files to the current directory.

Examples

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 directory /path/to/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 the file 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, it skips that file without overwriting it.

Extract files and overwrite existing files

unzip -o archive.zip

This command overwrites files with the same name that already exist in the target directory when extracting archive.zip, without prompting the user.

Extract without preserving the directory structure

unzip -j archive.zip

This command extracts all files in archive.zip to the current directory without preserving the original directory structure.

Precautions

  • unzipBy default, the original directory structure is preserved when extracting files. If you do not need to preserve the directory structure, you can use the-joption.
  • unzipYou can use the-xoption to exclude certain files or directories, which is useful for selectively extracting specific files.

Linux 命令大全Linux Command Collection

Other Extensions