Linux file compression and decompression commands to use the detailed

Source: Internet
Author: User
Tags execution extract zip file rar zip

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

Leave the Extract File permission information (the default is Superuser service only)

--preserve is the same as-p and-s

--same-owner Keep owner relationship consistent when trying to decompress (Superuser defaults)

-R,--append append file to end of archive

-U,--update only append files that are newer than the copy in the archive

-K, do not replace the existing file when--keep-old-files decompression

--keep-newer-files

Do not replace an existing file that is newer than the copy in the archive

--no-overwrite-dir preserves metadata for existing directories

Overwrite the existing file when--overwrite decompression

--overwrite-dir

Overwrite metadata for existing directories (default) when decompression

Clears the directory hierarchy before--recursive-unlink extract the directory

--remove-files Delete files after they are added 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 - -

The Linux system's default package contains no RAR compression tools, so we'll install RAR:

sudo apt-get install rar

  Option can only be entered from the given option (and only one), 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:

   section provides some 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 simple to write, so there is no notes to write, just look at the help document.

Linux Zip command detailed

Function Description: Compress file.

Syntax: Zip [-acddffghjjkllmoqrstuvvwxyz$][-b < working directory >][-ll][-n < word tail string >][-t < date time >][-< compression efficiency >][Compressed files [Document ...] [-i < template style] [-x < template style]

Supplemental Note: Zip is a widely used compression program, the file after it compression will produce a ". zip" extension of the compressed file.

Parameters

-A adjusts the executable automatic decompression file.

-b< working directory > Specifies the directory where files are temporarily stored.

-C adds a comment for each compressed file.

-d deletes the specified file from the compressed file.

The directory name is not established in the-D compressed file.

-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 will be added to the compressed file together.

-F attempts to repair a corrupted compressed file.

-G compresses the file and attaches it to the existing compressed file instead of creating a new compressed file.

-H online Help.

-i< template Style > compress only the eligible files.

-j only saves the file name and its contents, without any directory names.

-J Delete unnecessary data before compressing the file.

-K uses a file name in MS-DOS-compliant format.

-L replaces the LF character with the LF+CR character when compressing the file.

When-ll compressed files, replace the LF+CR characters with the LF character.

-L displays copyright information.

-M to compress the file and add the compressed file, delete the original file, that is, move the file to the compressed file.

-n< string > Do not compress files with a specific character end string.

-O Sets the time to change the compressed file to the same file as the file that has the latest change time in the compressed file.

-Q does not display the instruction execution process.

-R recursive processing of all files and subdirectories under the specified directory.

-S contains system and hidden files.

-t< Date Time > Set the date of the compressed file to the specified date.

-T checks that each file in the backup file is correct.

-U replaces the newer file with the compressed file.

-V Displays the instruction execution process or display version information.

-V Saves the file properties of the VMS operating system.

-W in the file name if the version number, this parameter is only valid under the VMS operating system.

-x< template style > exclude eligible files when compacting.

-X does not save additional file attributes.

-Y saves the symbolic connection directly, not the file that the connection points to, and this parameter is valid only for systems such as UNIX.

-Z Adds a comment for the compressed file.

-$ the volume name of the disk on which the first compressed file is stored.

-< 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.