In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the usage of the Linux basic command unzip". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of the Linux basic command unzip".
Unzip
Extract the files compressed by the zip instruction. Unzip lists, tests, or extracts files from the ZIP archive, which are usually found in the MS-DOS system. The default behavior (with no option) is to extract all files from the specified ZIP archive to the current directory (and the subdirectories below it). A companion program, zip (1L), creates ZIP files; both programs are compatible with PKWare's PKZIP and PKUNZIP files created for MS-DOS, but in many cases the program options or default behavior are different.
The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.
1. Grammar
Unzip [- Z] [- cflptTuvz [abjnoqsCDKLMUVWX$/: ^]] file [.zip] [file (s)...] [- x xfile (s)...] [- d exdir]
2. List of option parameters
Parameters.
Description
File [.zip]
The path to the ZIP archive. If the file specification is a wildcard, each matching file is processed in the order determined by the operating system (or file system). Only the file name can be a wildcard; the path itself cannot. Wildcard expressions are similar to those supported in common Unix shell (sh, ksh, csh) and may include:
*, which matches a sequence of 0 or more characters.
? To match one character
[.] To match any single character in parentheses; the range is specified by the start character, hyphen, and end character If it is an exclamation point or caret ('!' Or'^') after the left parenthesis, the range of characters in the parentheses is added (that is, any character is considered to match except those in parentheses). To specify a verbatim left parenthesis, you must use a three-character sequence of'[]'.
(be sure to reference any characters that may be interpreted or modified by the operating system, especially under Unix and VMS.) If no match is found, the specification is assumed to be a literal file name; if it also fails, the suffix .zip is appended. Note that, like any other ZIP archive, self-extracting ZIP files are supported; you only need to explicitly specify the .exe suffix, if any.
[file (s)]
An optional list of archive members to process, separated by spaces. (versions of VMS defined with VMSCLI must be separated by commas. See-v) in the option below. Regular expressions (wildcards) can be used to match multiple members; see above. Again, be sure to reference expressions that would otherwise be expanded or modified by the operating system
[- x xfile (s)]
An optional list of archive members to exclude from processing. Because wildcards usually match ('/') directory delimiters (see option-W for exceptions), this option can be used to exclude any files in subdirectories. For example, "unzip foo *. [Ch]-x * / *" will extract all C source files in the home directory, but not in any subdirectory. If there is no-x option, all C source files in all directories in the zip file are extracted.
[- d exdir]
An optional directory for extracting files. By default, all files and subdirectories are recreated in the current directory; the-d option allows extraction in any directory (it is always assumed that a directory has permission to write to that directory). This option does not need to appear at the end of the command line; it can also be accepted before the zipfile specification (with the general option), after the zip file specification, or between the file and the-x option. Options and directories can be connected together without any white space, but note that this may cause normal shell behavior to be suppressed. In particular,'- dumped'is extended by Unix C shell to the name of the user's home directory, but'- dumped'is considered a text subdirectory of the current directory'~'.
Note that in order to support outdated hardware, the use of the Unzip screen is limited to 22 or 23 lines, so it should only be seen as a reminder of the basic unzipping syntax, not an exhaustive list of all possible flags. A detailed list is as follows:
Option
Description
-- help
Help information
-- version
Display command version information
-c
Send the decompression result to standard output
-f
Update existing files when unzipping, that is, only those files that already exist on disk and are newer than disk copies. By default, the query is unzipped before overwriting, but the-o option can be used to suppress the query
-l
Displays the details of the files in the package. The name of the specified file, the size of the uncompressed file, the date and time it was modified, and the total of all specified files are printed.
-p
The decompression result is sent to standard output without character conversion. Only file data is sent to stdout, and files are always extracted in binary format
-t
Check the correctness of the compressed file. This option extracts each specified file in memory and compares the CRC (cyclic redundancy checksum, enhanced checksum) of the extended file with the stored CRC value of the original file.
-T
Set the timestamp on the archive to the timestamp of the latest file in each archive.
-u
Update existing files and create new files as needed. This option performs the same function as the-f option
-v
Lists the archive file (detailed format) or displays diagnostic version information.
-z
Only the comments for compressed files are displayed
Modifier
Description
-- help
Help information
-- version
Display command version information
-a
Character conversion of the text file during decompression
-b
Do not convert text file characters, treat all files as binary files.
-B
Save a backup copy of each overwritten file, and the old copy of 'foo' is renamed' foo~'.
-C
Set the file name to be case-sensitive when decompressing
-D
Skip timestamp recovery of extracted items.
-E
[MacOS only] displays the contents of the MacOS additional fields during the restore operation.
-F
[Acorn only] disables the removal of the NFS file type extension from the stored file name.
-I
[MacOS only] ignores file names stored in MacOS extra fields. Instead, use the most compatible file name stored in the generic section of the item title.
-j
Garbage road. The directory structure of the archive is not recreated; all files are stored in the extraction directory (current by default).
-J
[BeOS only] junk file attributes. The BeOS file properties of the file are not restored, only the data of the file.
-K
Preserve the SUID/SGID/duy file properties. Without this flag, these attribute bits are cleared for security reasons.
-L
Change the file name to lowercase when unzipping
-M
Send the decompression result to more split screen display.
-n
When decompressing, do not overwrite the original file
-N
Extract the file comments into an Amiga file.
-o
Overwrite the original file without prompting the user
-P
Enter the password when decompressing
-Q
Silent mode
S
[OS/2, NT, MS-DOS] convert spaces in file names to underscores
-S
[VMS] converts the text file (- amam Raaa) to the Stream_LF record format instead of the default variable length record format for the text file.
-U
[UNICODE_SUPPORT only] modify or disable UTF-8 processing.
-V
Keep (VMS) the file version number. VMS files can be stored with a version number in the format file.ext;#. By default, the'; # 'version number is deleted, but this option allows them to be retained.
-W
[the option is enabled only when WILD_STOP_AT_DIRR compiles] modify the pattern matching routine so that "?" And "*" do not match the directory delimiter "/".
-X
[VMS, Unix, OS/2, NT, Tandem] recover user and group information (UID/GID) under Unix
-Y
[VMS] treats the archived file name ending with ".nn" (where 'nnn' is a decimal number) as the VMS version number ('; nnn'). (the default is to treat them as file types.)
-$
[MS-DOS, OS/2, NT] if the extraction medium is removable (for example, a disk), the volume label is restored. The double option ($- $) allows fixed media (hard drive) to also be marked. By default, volume labels are ignored.
-/ extensions
[Acorn] overrides the extended list provided by the Unzip$Ext environment variable. During the extraction process, the file name extension that matches the items in this extension list is exchanged before the base name of the extracted file.
-:
Allows you to extract archive members to a location other than the current extract root folder.
-^
[Unix only] allows the names of extracted ZIP archive entries to contain control characters.
-2
[vms] forcibly and unconditionally convert file names to ODS 2-compatible names
3. Environmental options
The default behavior of unzip can be modified with options placed in the environment variable. This can be done with any option, but it may be most useful for the-a _ unzip _ L _ P _ Q _ ray _ quotation or-n modifier: by default, it causes unzip to automatically convert text files from uppercase to lowercase, making them match names insensitively, making them quieter, or having it always overwrite or not overwrite files when unzipping them. For example, to make the extraction as quiet as possible and report only errors, you can use one of the following commands:
Unix Bourne shell: UNZIP=-qq; export UNZIP
Unix C shell:setenv UNZIP-qq
OS/2 or MS-DOS:set UNZIP=-qq
VMS (quotes for lowercase): define UNZIP_OPTS "- qq"
In fact, environment options are considered to be the same as any other command-line options, except that they are actually the first option on the command line. To override the environment option, you can use the minus operator to delete it. For example, to override a mute flag in the example above, use the following command
Unzip-Q [other options] zipfile
The first hyphen is the normal switch character, and the second is the minus sign, which acts on the Q option. So, the effect here is to cancel a quiet quantum. To cancel these two quiet flags, you can use two (or more) minimum values:
Unzip-tmurq zipfile
Unzip-qt zipfile these two are equivalent
As suggested in the above example, the default variable name is UNZIP_OPTS, which is used for decompression of VMS and all other operating systems. UNZIP_OPTS is also accepted for compatibility with zip (1L) (don't ask). However, if both UNZIP and UNZIP_OPTS are defined, then UNZIP takes precedence. Unzip's diagnostic option (- v without a zip filename) can be used to check the values of all four possible decompression and zipinfo environment variables
4. Description
Some compiled versions of unzip may not support decryption. To check the encryption support version, you can try to test or extract the encrypted archive, or check the unzip diagnostic screen (see the-v option above) with "[decryption]" as one of the special compilation options.
As mentioned above, you can use the-P option to provide a password on the command line, but at the expense of security. The preferred decryption method is normal extraction; if the zip file member is encrypted, the decompression prompts for a password without echoing what you typed. Decompression continues to use the same password, as long as it looks valid, by testing a 12-byte header on each file. The correct password will always be checked out with the title, but there is a chance of 1DB 256, and an incorrect password will also. (this is a security feature of the PKWare zipfile format; it helps prevent brute force attacks, otherwise you can gain a great speed advantage just by testing the header.) If the wrong password is given, but it still passes the header test, an incorrect CRC is generated for the extracted data, or decompression fails during the extraction process, because the 'decrypted' bytes do not constitute a valid compressed data stream.
If the first password fails the header check of a file, unzipping prompts you for another password, and so on, until all files are extracted. If you do not know the password, enter an empty password (that is, return only one carriage return or 'Enter') as a signal to skip all further prompts. Only unencrypted files in the archive will then be extracted. (in fact, this is not entirely true; earlier versions of zip (1L) and zipcloak (1L) allowed empty passwords, so unzipping checks each encrypted file to see if the empty password is valid. This can lead to "false positives" and extraction errors, as described above.)
Files encrypted with 8-bit passwords (for example, passwords with accented European characters) may not be portable across systems and / or other archives. This problem stems from the use of multiple encoding methods for these characters, including Latin 1 (ISO 8859-1) and OEM code page 850. DoS PKZIP 2.04g uses OEM code pages; Windows PKZIP 2.50 uses Latin-1 (so it is not compatible with DOS PKZIP); Info-ZIP uses OEM code pages on DOS, OS/2, and Win3.x ports, but uses ISO encoding (Latin-1, etc.). Elsewhere, NicoMak's WinZip6.x does not allow 8-digit passwords at all. Try to first use the default character set (such as Latin-1) and then test the password with an alternate character set (such as the OEM code page).
5. Example code
Unzip letters
Extract letters.zip to the current directory and its subdirectories
Unzip-j letters
Extract the letters.zip to the current directory
Unzip-tq letters
Test the letters.zip, print out the test information, and determine whether the package is complete
Unzip-tq\ * .zip
Test all zip files in the current directory and print the sum information
Unzip-ca letters\ * .tex | more
To extract all members of a letters.zip whose name ends in .tex into standard output, automatically convert to a local line end convention, and pass the output to the more program
Unzip-p articles paper1.dvi | dvips
Extract the binaries to standard output and pipe them to another printer
Unzip source.zip "*. [fch]" Makefile-d / tmp
Extract all c and FORTRAN source files, as well as Makefile, to the / tmp directory
Unzip-C source.zip "*. [fch]" makefile-d / tmp
Extract all c and FORTRAN source files, as well as Makefile, to the / tmp directory (ignore all case)
Unzip-aaCL source.zip "*. [fch]" makefile-d / tmp
Extract any such file, but convert any uppercase name in ms-dos or vms to lowercase and convert the end of the line of all files to the local standard.
Unzip-fo sources
Extract only newer versions of files that already exist in the current directory without querying
Unzip-uo sources
Extract a newer version of the file that already exists in the current directory and create any files that do not already exist.
Unzip-v
To display the diagnostic screen, show which unzipped and zipinfo options are stored in the environment variable, whether the compilation and decryption support is in the environment variable, the compiler that compiles and decompresses, and so on
Unzip-l file.zip
Just list the content.
Unzip-ql file.zip
A doubly quiet list
Unzip-ql file.zip
Unzip-l Murq file.zip
Unzip-lmurq file.zip
Standard list
6. Diagnostic information
Exit code
Description
Normal, no error message
one
One or more warning errors were encountered, but the processing was completed successfully. This includes zip files that skip one or more files due to unsupported compression methods or encryption with unknown passwords.
two
A common error in the zip file format was detected. In any case, the processing may have been completed successfully; some corrupted zip files created by other archiving programs have a simple working environment.
three
A serious error in the zip file format was detected. Processing may fail immediately
four
Unzip cannot allocate memory for one or more buffers during program initialization.
five
Unzip cannot allocate memory, nor can it get TTY to read the decryption password.
six
Memory cannot be allocated to disk during unzip.
seven
Unzip was unable to allocate memory during memory decompression.
eight
This exit code is not currently used.
nine
The specified compressed file was not found
ten
Illegal option
eleven
No matching file was found
fifty
The disk is full.
fifty-one
The end of the ZIP archive was encountered prematurely.
eighty
The user terminates the decompression process using ctrl+c
eighty-one
The test or extraction of one or more files failed due to an unsupported compression method or unsupported decryption
eighty-two
No files were found due to the wrong decryption password. (however, even if a file is processed successfully, the exit status is 1.)
7. Examples
1) Show remarks
[root@localhost weijie] # zip 1.zip 1.c / / Compression
Adding: 1.c (deflated 9%)
[root@localhost weijie] # unzip-z 1.zip / / Show remarks
Archive: 1.zip
2) display the file information in the compressed package
[root@localhost weijie] # unzip-l 1.zip
Archive: 1.zip
Length Date Time Name
-
53 09-19-2018 16:08 1.c
--
53 1 file
3) decompression
[root@localhost weijie] # unzip-n-v 1.zip / / shows the decompression process
Archive: 1.zip
Length Method Size Cmpr Date Time CRC-32 Name
53 Defl:N 48 9% 09-19-2018 16:08 1c3e46be 1.c
-
53 48 9% 1 file
Thank you for your reading, the above is the content of "the usage of the Linux basic command unzip". After the study of this article, I believe you have a deeper understanding of the usage of the Linux basic command unzip, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.