Linux_ Compressed files and directories

Source: Internet
Author: User

Compression Decompression Command:

compression format: gz,bz2,xz,zip,z

Compression algorithm: Different algorithms, compression ratios will also be different:

Compress::filename. Z

Uncompress

Currently the most popular compression tools:

gzip:. GZ only files can be compressed

gzip/path/to/somefile/ Delete source files after compression

- D also means decompression

-# : [1-9], Specify the compression ratio, which is the default 6

Gunzip

gunzip/path/to/somefile.gz The source file is deleted when the extract is finished

zcat/path/to/somefile.gz without pressure, view the contents of the text file

bzip2:. bz2 than gzip compression tool with a greater compression ratio, using a format approximation

Bzip2/path/to/somefile source files are also deleted after compression

- D Unzip

      -# : [1-9], default 6

- k Keep Source Files

[Email protected]]# bzip2-d-K fstab.bz2

[Email protected]]# ls

ABC B2 fstab fstab.bz2

Bunzip2/path/to/somefile Unzip

Bzcat , in the case of uncompressed, view bzip2 the text class compressed file

XZ:. XZ

Xz/path/to/somefile source files are also deleted after compression

–d Unzip

-# [1-9], Specify compression ratio, default 6

- k source files can also be preserved when compressing

Unxz Unzip

Xzdec

Xzcat in the case of uncompressed, view XZ the text class compressed file

Zip: compression tool, compression ratio is not small. You can compress a directory , You can compress multiple files together, and compress the source files without deleting them

Zipfilename.zip FILE1 FILE2 ...

Unzip Filename.zip do not delete source files after decompression

Archive: Archive, the archive itself does not imply a compression

Tar: Archive-only No compression (do not delete source files after archiving)

- C Create an archive file

- F File.tar archived files for operations ( archive name must be established )

[Email protected]]# tar-cf Skel.tar Skel

[[Email protected]]# LS-LH

Total Dosage 40K

-rw-r--r--. 1 rootroot 10K 6 Month 15:28skel.tar

- x Restore archive, do not delete archive file

[Email protected]]# tar-xf Skel.tar

[Email protected]]# ls

Fstab.xz Skel Skel.tar

--xattrs preserves extended attribute information for files while archiving

- T do not expand archive See which files are archived

[Email protected]]# tar-cf V.tar a b c D

[Email protected]]# tar-tf V.tar

A/

b/

c/

d/

[email protected]]# xz V.tar (both archived and compressed)

[[Email protected]]# LS-LH

Total Dosage 48K

-rw-r--r--. 1 rootroot 184 6 Month 15:38v.tar.xz

-ZCF: Archive and Invoke gzip Compression

[Email protected]]# tar-zcf abcd.tar.gz a b c D

[Email protected]]# ls

A abcd.tar.gz b c D

-XCF called gzip Unzip and expand the archive

-JCF called bzip2

[Email protected]]# tar-jcf abcd.tar.bz2 a b c D

[Email protected]]# ls

A abcd.tar.bz2 b c D

-JXF Unzip

-JCF called XZ

[Email protected]]# tar-jxf abcd.tar.xz a b c D

[Email protected]]# ls

A ABCD.TAR.XZ b c D

-JXF Unzip

It's a lot of time when you unzip. -j or -j or - Z can not write

tar-ztfabcd.tar.gz do not expand directly look inside the content, the same here Z or J or J can omit

Cpio : Archive Tool

[Email protected]]# file/boot/initramfs-2.6.32-504.el6.i686.img/boot/initramfs-2.6.32-504.el6.i686.img: gzipcompressed data, from Unix, last Modified:mon June 6 17:35:04, Max compression

[[Email protected]]# cp/boot/initramfs-2.6.32-504.el6.i686.img/tmp Copy this compressed file to / tmp under

[[Email protected]]# mv Initramfs-2.6.32-504.el6.i686.img initramfs-2.6.32-504.el6.i686.img.gz

[email protected]]# gzip-d initramfs-2.6.32-504.el6.i686.img.gz Unzip

[Email protected]]# ls

A abcd.tar.gz b c D initramfs-2.6.32-504.el6.i686.img

[[Email protected]]# file initramfs-2.6.32-504.el6.i686.img View File Types to be Cpio Archived Files

Initramfs-2.6.32-504.el6.i686.img:ascii Cpio Archive (SVR4 with no CRC)

Exercise: Write a script

Let the user enter several file names from the keyboard, and the script can archive and compress the files into a single file:

#!/bin/bash

Read-p "Threefiles:" FILE1 FILE2 FILE3

Read-p "Destination:" DEST

Read-p "Compress[gzip|bzip2|xz]:" COMP

Case $COMP in

Xz

TAR-JCF${DEST}.TAR.XZ $FILE 1 $FILE 2 $FILE 3

;;

Gzip

tar-zcf${dest}.tar.gz $FILE 1 $FILE 2 $FILE 3

;;

BZIP2)

TAR-JCF${DEST}.TAR.BZ2 $FILE 1 $FILE 2 $FILE 3

;;

*)

echo "Unknown."

Exit 2

;;

Esac


This article from "Linux operation and Maintenance" blog, declined reprint!

Linux_ Compressed files and directories

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.