In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
ZIP is the most widely used archive file format and supports lossless data compression. A ZIP file is a data container that contains one or more compressed files or directories.
In this tutorial, we will show you how to use the unzip command to extract files on a Linux system from the command line.
What is unzip?
Unzip is a utility that helps you list, test, and extract compressed ZIP archives.
Installation and decompression
Unzip is not installed by default in most Linux distributions, but you can easily install it using the package manager of the distribution.
Install unzipped on Ubuntu and Debian
Sudo apt install unzip
Install unzipped on CentOS and Fedora
How sudo yum install unzip unzips ZIP files
It is the easiest form to use without any option, and the unzip command extracts all files from the specified ZIP archive to the current directory.
Unzip filename.zip
In order to be able to extract ZIP archives in a specific directory, the user needs to have write access to that directory.
ZIP files do not support Linux-style ownership information, and all extracted files will be owned by the user running the command.
For example, suppose you downloaded the WordPress installation ZIP file (https://wordpress.org/latest.zip). To extract this file to the current directory, simply run the following command:
How unzip latest.zip suppresses the output of unzip commands
By default, the unzip command prints the names of all files it extracts and a summary when the extraction is complete.
Use the-Q option to disable printing of these messages.
Unzip-Q filename.zip how to extract the ZIP file to another directory
To extract the ZIP file to a different directory than the current directory, use this-d option.
Unzip filename.zip-d / path/to/directory
For example, to extract the latest.zip from the WordPress archive to the / var/www/ directory, you would use the following command:
Sudo unzip latest.zip-d / var/www
We used sudo in the above command because in most cases, the user we logged in did not have write access to the / var/www directory. When you extract the ZIP file using sudo, the extracted files and directories are owned by the user root.
How to extract password-protected ZIP files
To extract password-protected files, use the-P option followed by the password.
How to exclude files when unzip-P PasswOrd filename.zip unzips ZIP files
Use this-x option if you want to extract all but one file from the ZIP archive.
Unzip filename.zip-x file-to-exclude
In the following example, we will extract all files and directories from the ZIP archive except the .git directory:
Unzip filename.zip-x "* .git / *" how to overwrite existing files when using decompression
Suppose you have unzipped the ZIP file when you run the same command again.
Unzip latest.zip
By default, Unzip asks if you want to overwrite the current file, overwrite all files, skip the extraction of the current file, skip the extraction of all files, or rename the current file.
Archive: latest.zipreplace wordpress/xmlrpc.php? [y] es, [n] o, [A] ll, [N] one, [r] ename:
If you want to overwrite an existing file without prompting, use the-o option:
Unzip-o filename.zip
Please use this option carefully. The file will be overwritten and if you make any changes to the file, the changes will be lost.
How to extract a ZIP file without overwriting an existing file
Suppose you have unzipped a ZIP file and made changes to some files, but you accidentally deleted some files. You want to keep the changes and restore the deleted files from the ZIP archive.
In this case, you want to use the-n option to skip the extraction of existing files.
Unzip-n filename.zip how to extract multiple ZIP files
If there are multiple ZIP files in the current working directory, you can extract them all with a single command:
Unzip'* .zip'
Note the single quotation marks around * .zip. If you forget to reference the parameter, shell will expand the wildcard and you will receive an error.
How to list the contents of a Zip file
To list the contents of the ZIP file, use the-l option.
Unzip-l filename.zip
In our example, we list all WordPress installation files by executing the following command:
Unzip-l latest.zip
The output will look like this:
Archive: latest.zip Length Date Time Name--0 2018-08-02 22:39 wordpress/ 3065 2016-08-31 18:31 wordpress/xmlrpc.php 364 2015-12-19 12:20 wordpress/wp-blog-header.php 7415 2018-03-18 17:13 wordpress/readme.html. 21323 2018-03-09 01:15 wordpress/wp-admin/themes.php 8353 2017-09-10 18:20 wordpress/wp-admin/options-reading.php 4620 2017-10-24 00:12 wordpress/wp-trackback.php 1889 2018-05-03 00:11 wordpress/wp-comments-post.php--27271400 1648 files conclusion
You have learned how to extract ZIP files and the most common decompression options. To create a ZIP archive on a Linux system, you need to use the zip command.
Original link: https://www.linuxprobe.com/linux-unzip.html
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.