In Linux systems, the file compression commands we typically use are: BUNZIP2, bzip2, Cpio, Gunzip, gzip, split (cut file), Zgrep (look for matching regular expressions in compressed files), zip, unzip, tar, R Ar.
The last four are more commonly used by me, today's notes on the writing of these four good.
1, Tar:
Tar command: Tar [options ...] [FILE] ...
Enter "Tar-?" For help information, Tar's help documentation is shown as follows:
Example
TAR-CF Archive.tar Foo Bar # Create archive file Archive.tar from file foo and bar.
TAR-TVF Archive.tar # Details all the files in the archive file Archive.tar.
TAR-XF Archive.tar # Expands all the files in the archive file Archive.tar.
If you want to compress a folder, enter:
TAR-CVF Dirarchive.tar/dirname
Similarly, to extract an archive to a specific folder, you would:
TAR-XVF Dirarchive.tar/dirname
Next review. Let's make a folder out of it and put a few folders and files in it:
We first create a tar file, first compress a folder (TestDir):
TAR-CF Testdir.tar TestDir
The structure in the compressed package is then listed:
Then we append the file to this compressed package:
Of course, the above single-step operation does not need to do, the compression package already has this file.
And then look at the structure in this compressed package:
If you use the-v option in the example, all the file attributes in the compressed package are listed. Include permissions, creator, byte size, modified time, and filename:
Extract and display a list of files from the tar compressed file:
Generally, the options that are commonly used are the main operation options:
and practice some of the other uses:
1. When compressing the TestDir directory, you need to exclude the test file in the root path of the folder:
2. Compress only files that are newer than the specified time:
3, compressed all file names prefixed with "TE" files or folders (or compressed suffix is "st" file):
Finally, add the usual options:
-P,--preserve-permissions,--same-permissions
Reserve the Extract File permission information (the default is Superuser service only)
--preserve as-p and-s
--same-owner keep Owner's relationship consistent when trying to decompress (Superuser defaults)
-R,--append append file to end of archive
-U,--update append only files that are newer than those in the archive
-K,--keep-old-files do not replace the existing file
--keep-newer-files
When extracting & nbsp; do not replace an existing file that is newer than the copy in the archive
- no-overwrite-dir preserves metadata for existing directories
--overwrite Rewrite existing files when extracting
- Overwrite-dir
overwrite metadata for existing directory (default)
--recursive-unlink Clear directory hierarchy before extracting directory
--remove-files delete them after adding files to the archive
-N,--newer=date-or-file,--after-date=date-or-file save only files that are newer than date-or-file
2, RAR:
RAR <command>-<switch 1>-<switch n> <archive> <files...>< @listfiles ...> <path _to_extract>
The Linux system's default package contains no RAR compression tools, so we'll install RAR:
sudo apt-get install rar
<command> option can only enter one (and only one) from the given option, let's take a look at the list of commands it provides:
For example, now we're going to file compression:
After the compression is complete, we can obtain the specific structure information in the compressed file by command L:
You can even print all the information in a compressed file to the console by using the command p:
The <switch n> section provides a number of functional options.
For example, to update the compressed file in an additional way can be selected-ad:
Or if you want to exclude a file from the outside, you can use switch-X (note that the string to be excluded is immediately following the x, without any symbols), such as we want to exclude files that start with the root path of the folder under "TE":
There is also encryption, with the switch-p, the same password followed by P can:
If the file is uncompressed or opened directly, you will be asked to enter the password:
In addition, there are some common options:
Ag[format] Generate archive name using the current date
CL Convert names to lower case
CU Convert names to upper case
DF Delete Files after archiving
Ed do not add empty directories
DW Wipe files after archiving
Other commands and switches can refer to the Help manual.
3, Zip, unzip:
Zip [-options] [-B path] [-t mmddyyyy] [-N suffixes] [zipfile list] [-xi list]
Unzip [-z] [-opts[modifiers]] file[.zip] [list] [-X xlist] [-D Exdir]
The use of
zip and unzip is simpler, and even the help document is easy to write, so there's no notes to write, just look at the help document.
Linux zip commands detailed
Feature description: Compress files. &NBSP
Syntax: Zip [-acddffghjjkllmoqrstuvvwxyz$][-b < working directory >][-ll][-n < word tail string >][-t < date time >][-< compression efficiency >][compressed file [file ...] [-i < template style] [-x < template style >]
Supplemental Note: Zip is a widely used compression program that compresses the file to produce a compressed file with a ". zip" extension.
Parameter:
-A adjusts the automatic uncompressed files that are executable. &NBSP
-b< Working directory > Specifies the directory where files are temporarily stored. &NBSP
-C adds a comment for each compressed file. &NBSP
-D deletes the specified file from the compressed file. The directory name is not established in the &NBSP
-D compressed file. &NBSP
-F The effect of this parameter is similar to the specified "-u" parameter, but not only the existing file is updated, but if some files do not exist in the compressed file, this parameter is added to the compressed file together. &NBSP
-F attempts to repair a corrupted compressed file. &NBSP
-G compresses the file and attaches it to the existing compressed file instead of creating a new compressed file. &NBSP
-H online Help. &NBSP
-i< template style > compress only the eligible files. &NBSP
-j saves only the file name and its contents, without any directory names. &NBSP
-j Deletes unnecessary data before the compressed file. &NBSP
-K uses a file name in MS-DOS-compliant format. &NBSP
-L compresses the file by replacing the LF character with the LF+CR character. &NBSP
-ll The LF+CR character to the LF character when compressing the file. &NBSP
-L displays copyright information. &NBSP
-M compresses the file and joins the compressed file, deletes the original file, and moves the file to the compressed file. &NBSP
-n< string > Do not compress a file with a specific character end string. &NBSP
-O sets the time to change the compressed file to the same file as the file with the latest change time in the compressed file. &NBSP
-Q does not display the instruction execution process. &nbsP
-R recursively handles all files and subdirectories under the specified directory. &NBSP
-S contains system and hidden files. &NBSP
-t< Date Time > Set the date of the compressed file to the specified date. &NBSP
-T checks to see if each file in the backup file is correct. &NBSP
-U replaces the newer file in the compressed file. &NBSP
-V displays an instruction execution procedure or displays version information. &NBSP
-V Saves the file properties of the VMS operating system. &NBSP
-W in the file name if the version number, this parameter only valid under the VMS operating system. &NBSP
-x< Template styles > Compression to exclude eligible files. &NBSP
-X does not save additional file attributes. &NBSP
-y Saves the symbolic connection directly, not the file that the connection points to, and this parameter is only valid under systems such as UNIX. &NBSP
-Z Adds a comment for the compressed file. &NBSP
-$ The volume name of the disk on which the first compressed file was saved. &NBSP
-< Compression efficiency > Compression efficiency is a value between 1-9.
Linux Unzip command detailed
Function Description: Extract zip file
Syntax: Unzip [-cflptuvz][-agcjlmnoqsvx][-p < password >][.zip file] [file][-d < directory >][-x < file] or unzip [-z]
Supplemental Note: Unzip is the decompression program for the. zip compressed file.
Parameters
-C Displays the uncompressed results to the screen and converts the characters appropriately.
-F to update existing files.
-L Displays the files contained within the compressed file.
-P, similar to the-c parameter, displays the uncompressed results to the screen, but does not perform any transformations.
-T check that the compressed file is correct.
-U is similar to the-f parameter, but in addition to updating an existing file, the other files in the compressed file are uncompressed to the directory.
-V displays detailed information when it is executed.
-Z Displays only the memo text for the compressed file.
-A makes the necessary character conversions to the text file.
-B Do not convert text files to characters.
The file name in the-C compressed file is case-sensitive.
-J does not handle the directory path in the compressed file.
-L Change all file names in the compressed file to lowercase.
-M sends output to more program processing.
-N uncompressed does not overwrite the original file.
-O does not need to ask the user first, overwriting the original file after unzip execution.
-p< Password > Use zip password option.
-Q does not display any information at execution time.
-S converts the whitespace character in the file name to the bottom line character.
-V preserves file version information for VMS.
-X to save the original uid/gid of the file while decompressing.
[. zip file] Specifies a. zip compressed file.
[file] Specifies which files in the. zip compressed file to process.
-d< directory > Specifies the directory to store after the file is uncompressed.
-x< file > Specify which files in the. zip compressed file should not be processed.
-Z unzip-z equals execute zipinfo Instruction
Example:
The zip command can be used to compress files into a commonly used zip format. The unzip command is used to extract the zip file.
1. I want to compress a file abc.txt and a directory dir1 into Yasuo.zip:
# zip-r Yasuo.zip abc.txt Dir1
2. I downloaded a yasuo.zip file and wanted to decompress:
# Unzip Yasuo.zip
3. My current directory has abc1.zip,abc2.zip and abc3.zip, I would like to decompress them together:
# Unzip ABC? Zip
Note:? Represents a character, if you use * to represent any number of characters.
4. I have a large compressed file Large.zip, I don't want to decompress, just want to see what's inside it:
# unzip-v Large.zip
5. I downloaded a compressed file large.zip to verify that the compressed file is completely downloaded
# unzip-t Large.zip
6. I use the-v option to find that there are many directories and subdirectories in the Music.zip compressed file, and the subdirectories are in fact songs mp3 files, I would like to download these files to the first level of the directory, rather than a layer of building a directory:
# unzip-j Music.zip