How to use Linux compression packaging commands

Source: Internet
Author: User
Tags bz2 file size

Parameters:

-C: Create a compressed file parameter instruction (create meaning);

-x: Unlock a parameter command for a compressed file!

-T: View the files inside the Tarfile!

In particular, in the release of the parameters, c/x/t can only exist one! Cannot exist at the same time!

Because it is not possible to compress and decompress at the same time.

-Z: Do you also have gzip properties? That is, is it necessary to use gzip compression?

-j: Do you have bzip2 properties at the same time? Is it necessary to use BZIP2 compression?

-V: Displaying files during compression! This is commonly used, but is not recommended in the context of the implementation process!

-F: Use file name, please note that after F to immediately receive file name Oh! No more Parameters!

For example, the use of "TAR-ZCVFP tfile sfile" is the wrong way to write

"TAR-ZCVPF tfile sfile" is right!

-P: Use the original properties of the original file (properties will not be changed according to the user)

-P: You can use absolute paths to compress!

-N: Newer than the following date (YYYY/MM/DD) will be packaged into the newly created file!

--exclude file: Do not package file in the process of compression!

Example:

Example one: Package all the files in the/etc directory into a/tmp/etc.tar

[Root@linux ~]# Tar-cvf/tmp/etc.tar/etc

gzip, Zcat command

[Root@linux ~]# gzip [-cdt#] File name

[Root@linux ~]# zcat file name. gz

Parameters:

-C: Output the compressed data to the screen, can be handled through the data flow redirect;

-D: the extracted parameters;

-T: can be used to verify the consistency of a compressed file ~ To see if there are errors;

-#: Compression level,-1 the fastest, but compression is the worst,-9 slowest, but the best compression ratio! Preset IS-6 ~

Example:

Example one: Copy/etc/man.config to/tmp and compress with gzip

[Root@linux ~]# Cd/tmp

[Root@linux tmp]# Cp/etc/man.config.

[Root@linux tmp]# gzip Man.config

# now Man.config will turn into man.config.gz!

Example two: Read the file contents of sample one!

[Root@linux tmp]# Zcat man.config.gz

# At this time, the screen will show the contents of the file after man.config.gz decompression!!

Example three: Unzip the file of example one

[Root@linux tmp]# gzip-d man.config.gz

Example four: Man.config with the best compression ratio of the example triple untie and keep the original file

[Root@linux tmp]# gzip-9-C man.config > man.config.gz

bzip2, Bzcat command.

[Root@linux ~]# bzip2 [-cdz] File name

[Root@linux ~]# bzcat file name. bz2

Parameters:

-C: Output The compressed process data to the screen!

-D: Uncompressed parameters

-Z: Compressed parameters

-#: The same as gzip, are in the calculation of the compression ratio of the parameters,-9 best,-1 fastest!

Example:

Example one: Compress the/tmp/man.config just to bzip2

[Root@linux tmp]# bzip2-z Man.config

# now Man.config will turn into MAN.CONFIG.BZ2!

Example two: Read the file contents of sample one!

[Root@linux tmp]# Bzcat man.config.bz2

# At this time, the screen will show the contents of the file after man.config.bz2 decompression!!

Example three: Unzip the file of example one

[Root@linux tmp]# bzip2-d man.config.bz2

Example four: Man.config with the best compression ratio of the example triple untie and keep the original file

[Root@linux tmp]# bzip2-9-C man.config > man.config.bz2

Compress command

[Root@linux ~]# compress [-DCR] file or directory

Parameters:

-D: Parameters to decompress

-R: It can be compressed together with the files in the directory!

-C: The output of the compressed data into standard outputs (output to the screen)

Example:

Example one: Duplicate/etc/man.config to/tmp and compress

[Root@linux ~]# Cd/tmp

[Root@linux tmp]# Cp/etc/man.config.

[Root@linux tmp]# Compress Man.config

[Root@linux tmp]# Ls-l

-rw-r--r--1 root root 2605 11:43 man.config.z

Example two: Unlock the file that just zipped

[Root@linux tmp]# compress-d man.config.z

Example three: Compress man.config into another file to back up

[Root@linux tmp]# compress-c man.config > Man.config.back.z

[Root@linux tmp]# ll man.config*

-rw-r--r--1 root root 4506 11:43 man.config

-rw-r--r--1 root root 2605 11:46 man.config.back.z

# The parameter of this-C is more interesting! He will output the data of the compression process to the screen instead of writing it as

# file. Z file. So, we can make the data output into another file name through the data flow redirection method.

# about Data Flow redirection, we'll talk about it in the bash shell!

DD command

[Root@linux ~]# dd if= "input_file" of= "Outptu_file" bs= "Block_size"

count= "Number"

Parameters:

If: is input file Hello ~ can also be a device Oh!

Of: is output file Oh ~ can also be a device;

BS: Planning the size of a block, if not set, the preset is the bytes

Count: How many BS mean.

Example:

Example one: Backup/etc/passwd to/tmp/passwd.back

[Root@linux ~]# DD if=/etc/passwd of=/tmp/passwd.back

3+1 Records in

3+1 Records out

[Root@linux ~]# Ll/etc/passwd/tmp/passwd.back

-rw-r--r--1 root root 1746 Aug 14:16/etc/passwd

-rw-r--r--1 root root 1746 Aug 16:57/tmp/passwd.back

# Take a closer look, my/etc/passwd file size is 1746 bytes, because I didn't set BS,

# So the preset is the bytes for a unit, so the upper 3+1 says there are 3 complete

# The bytes of the bytes, and the other block of the not-so-full!

# In fact, it feels like the CP Directive ~

Example two: The MBR of backup/dev/hda

[Root@linux ~]# dd If=/dev/hda of=/tmp/mbr.back bs=512 count=1

1+0 Records in

1+0 Records out

# It's going to take a good look ~ we know the MBR of the entire hard drive is a bytes,

# is the first sector on the hard drive, so I can use this to

# All the information in the MBR is recorded, it's really awesome! ^_^

Example three: Backup the entire/DEV/HDA1 partition.

[Root@linux ~]# DD if=/dev/hda1 OF=/SOME/PATH/FILENAEM

# This is a very good command! Back up the entire partition content.

# followed by must not be in the/DEV/HDA1 directory AH ~ Otherwise, how to read can not read the end ~

# This action is very effective, if another day you have to complete the whole partition to fill in the contents,

# You can use the DD if=/some/file of=/dev/hda1 to write data to the hard disk.

# If you want an entire hard disk backup, like Norton's Ghost software,

# from disk to disk, hey, you can use DD ~ powerful!

Cpio command

[Root@linux ~]# cpio-covb > [File|device]

[Root@linux ~]# Cpio-icduv

Parameters:

-O: Output data Copy to a file or appliance

-I: Copy the data from the file or device to the system

-T: View the contents of a file or appliance created by Cpio

-C: A newer type of portable format storage

-V: Allow file names to be displayed on the screen during storage

-B: Let the preset Blocks can be increased to 5120 bytes, preset is bytes!

The advantage of this is that you can speed up the storage of large files (refer to the I-nodes concept)

-D: Automatically create the directory! Since Cpio content may not be in the same directory,

If so, there will be a problem with the reverse backup process! This time plus-D,

You can automatically set up the directory you need!

-U: Automatically overwrite older files with newer ones!

Example:

Example one: Write all the information on the system to the tape drive!

[Root@linux ~]# Find/-print | Cpio-covb >/dev/st0

# in general, a tape drive that uses a SCSI interface, the code name is/dev/st0 Oh!

Example two: Check what files are on the tape drive?

[Root@linux ~]# CPIO-ICDVT

[Root@linux ~]# Cpio-icdvt/tmp/content

# in the first action, the file in the tape drive will be listed on the screen, and we can go through the second action,

# All the file names are recorded to/tmp/content files!

Example three: Restore the data on the tape back ~

[Root@linux ~]# Cpio-icduv

# in general, a tape drive that uses a SCSI interface, the code name is/dev/st0 Oh!

Example four: All the "files" underneath the/etc are backed up into/root/etc.cpio!

[Root@linux ~]# Find/etc-type F | Cpio-o >/root/etc.cpio

# so it can be backed up ~ You can also cpio-i the data

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.