Linux unzip command introduction
unzip
Commands are used in Linux to decompress compressed files in .zip format. It is the most widely used compressed file format that supports lossless data compression. A .zip file is a data container containing one or more compressed files or directories that can be extracted later to restore the original file.
Linux version that applies to the unzip command
unzip
The command is not installed by default in most Linux distributions, but you can easily install it using your distribution's package manager. The following is installed in different Linux distributionsunzip
Command method:
[linux@ ~]$ sudo apt install unzip #Ubuntu and Debian
[linux@ ~]$ sudo yum install unzip #CentOS and Fedora
Basic syntax of Linux unzip command
unzip
The basic syntax of the command is as follows:
unzip [option] zip_file
If you don't have any optionsunzip
Command to unzip the .zip file, it will unzip all files to the current directory.
Common options or parameter descriptions of Linux unzip commands
The following isunzip
Some common options for commands:
Options | illustrate |
---|---|
-q | Used to suppress message output during decompression |
-d /path/to/directory | Specify the target directory for the decompressed file |
-P password | If the .zip file is password protected, use this option to specify the password required to open the file |
Detailed explanation of Linux unzip command instance
Here are someunzip
Example of the command:
Example 1: Unzip the .zip file
If you downloaded a .zip file, e.g., and want to unzip it to the current directory, you can run the following command:
[linux@ ~]$ unzip
Example 2: Unzip the .zip file to the specified directory
If you want to unzip the contents of the .zip file to a directory other than the current working directory, you can use-d
Options. This allows you to specify the path to the target directory.
[linux@ ~]$ unzip -d /var/www
Example 3: Unzip password protected .zip file
If you have a password protected .zip file and you want to extract its contents, you can useunzip
Commands and-P
Options. This option allows you to specify the password you need to open the file.
[linux@ ~]$ unzip -P PasswOrd
Example 4: Unzip the .zip file and overwrite the existing file
If you want to unzip a .zip file and want to overwrite any existing files, you can use-o
Options.
[linux@ ~]$ unzip -o
Example 5: List the contents of .zip files
If you just want to view the contents of the .zip file without actually decompressing it, you can use-l
Options.
[linux@ ~]$ unzip -l
Example 6: Test the integrity of .zip file
If you want to test the integrity of the .zip file, you can use-t
Options.
[linux@ ~]$ unzip -t
Example 7: Unzip a specific file in a .zip file
If you just want to unzip specific files from the .zip file, you can specify the names of those files on the command line.
[linux@ ~]$ unzip
Example 8: Unzip a specific file in the .zip file to a specified directory
If you want to unzip a specific file from the .zip file to the specified directory, you can use it in conjunction with it-d
Options and file names.
[linux@ ~]$ unzip -d /var/www
Example 9: Unzip all files in the .zip file, except for specific files
If you want to unzip all files in the .zip file, except for some specific files, you can use-x
Options.
[linux@ ~]$ unzip -x
Example 10: Unzip all files in the .zip file, except for the specific files to the specified directory
If you want to unzip all files in the .zip file, except for some specific files to the specified directory, you can use it in conjunction with-d
Options,-x
Options and file names.
[linux@ ~]$ unzip -x -d /var/www
Example 11: Unzip all files in the .zip file, only those newer than the target file
If you want to unzip all files in the .zip file, but only unzip those newer than the target file, you can use-u
Options.
[linux@ ~]$ unzip -u
Example 12: Unzip all files in the .zip file, and only those files that are newer than the target file to the specified directory
If you want to unzip all files in the .zip file, but only unzip those newer than the target file to the specified directory, you can use it in conjunction with-d
Options and-u
Options.
[linux@ ~]$ unzip -u -d /var/www
Example 13: Unzip all files in the .zip file, and only those files that are newer than the target file or do not exist.
If you want to unzip all files in the .zip file, but only those files that are newer than the target file or do not exist, you can use-n
Options.
[linux@ ~]$ unzip -n
Example 14: Unzip all files in the .zip file, and only those files that are newer than the target file or do not exist to the specified directory.
If you want to unzip all files in the .zip file, but only unzip files that are newer than the target file or do not exist to the specified directory, you can use it in conjunction with-d
Options and-n
Options.
[linux@ ~]$ unzip -n -d /var/www
Example 15: Unzip all files in the .zip file, only those files that are newer than the target file or do not exist, except for specific files.
If you want to unzip all files in the .zip file, but only those files that are newer than the target file or do not exist, you can use it in conjunction with some specific files.-x
Options and-n
Options.
[linux@ ~]$ unzip -n -x
Example 16: Unzip all files in the .zip file, and only those files that are newer than the target file or do not exist, except for specific files to the specified directory.
If you want to unzip all files in the .zip file, but only unzip files that are newer than the target file or do not exist, except for some specific files to the specified directory, you can use it in conjunction with-d
Options,-x
Options and-n
Options.
[linux@ ~]$ unzip -n -x -d /var/www
Notes on Linux unzip commands
-
unzip
The command does not store ownership information. The extracted file is owned by the user who ran the command. - You must have write permissions in the directory where you are decompressing the .zip file.
- This is insecure when you enter your password on the command line and should be avoided. A safer option is not to use
-P
Option to run the command. If the .zip file is password protected,unzip
You will be prompted to enter your password.
Linux unzip related commands
Here are some withunzip
Command-related commands:
- zip command: used to create .zip compressed files
- tar command: used to process .tar files
- gzip command: used to compress or decompress .gz files
- gunzip command: used to decompress .gz file
- bzip2 command: used to compress or decompress .bz2 files
- xz command: used to compress or decompress .xz files
- lzma command: used to compress or decompress .lzma files
- rar command: used to process .rar files
- unrar command: used to decompress .rar file
- 7z command: used to process .7z files