Linux compression and archiving

Source: Internet
Author: User
Tags bz2

Basic concepts:

Compression: The file according to some algorithm to reduce, such as a text file content is: AAAAADDDD We can simplify it as a5d4 need to restore back, so that the original text storage needs 18 Bytes, now only need 8 bytes, greatly save space, generally speaking, the simpler the compression algorithm, The faster the compression speed, the more complex the algorithm, the higher the compression ratio [(the size before compression-the size after compression)/the size before compression).

Archive (archive): Compression can only compress the file, but not the directory, and archiving is the collection of multiple files together to form a file, so that we can put the directory, and the contents of the directory is archived together to form a file, and then we can use the tool to compress it. (Note: The archive itself is not compressed)


Compression command:

Compress:filenme.z

Uncompress


Gzip:.gz

Gzip/path/to/somefile Delete source files after compression is complete

-D: Unzip

-#: Specify the compression level, [1-9] 1 The fastest compression ratio is lowest, 9 the slowest compression ratio is the highest, the default is 6

zcat/path/to/somefile.gz View Text File contents

BZIP2:. bz2

Compression tool with a greater compression ratio than gzip

Bzip2/path/to/somefile

-D:

-#:

-K: Keep the original file when compressing

bunzip2/path/to/somefile.bz2

Bzcat


XZ:. XZ

Xz/path/to/somefile

-D

-#:

-K: Compressed retention source file

Unxz

Xzcat

Xzdec


Zip: A compressed and archived tool

Zip filename.zip FILE1 FILE2 ... : The original file is not deleted after compression

Unzip Filename.zip


Tar: Archive tool

-C: Create an archive file

-F File.tar: Archived files for operations

-X: Expand Archive

--xattrs: Preserves extended attribute information for files when archiving

-T: Do not expand the archive to directly see which files are archived


-ZCF: Archive and invoke gzip compression

-ZXF: Call gzip to unzip and expand Archive,-Z option to omit


-jcf:bzip2

-JXF:


-jcf:xz

-JXF:


Exercise: Write a script

From the keyboard allows the user to enter several files, the script can archive this several files into a file

Read

-P "PROMPT": Give a hint



This article from "Single Season rice" blog, declined reprint!

Linux compression and archiving

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.