Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Linux Compression Packaging Command

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Linux compression packaging command use method", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn the "Linux compression packaging command use method"!

Parameters:

-c: parameter instruction to create a compressed file (create);

-x: Unpack a compressed file parameter instruction!

-t: Check the files in tarfile!

Note in particular that only one c/x/t can exist in the parameter release! They cannot exist at the same time!

Because it's impossible to compress and decompress at the same time.

-z: Does it also have the property of gzip? Does it need to be compressed with gzip?

-j: Does it also have the property of bzip2? Does it need to be compressed with bzip2?

-v: Display files during compression! This is commonly used, but not recommended for background execution!

-f: Use file name, please note, immediately after f to continue file name oh! No more parameters!

For example, using tar -zcvfP tfile sfile is the wrong way to write it.

"tar -zcvPf tfile sfile" is right!

-p: Use the original attributes of the original file (attributes do not change by user)

-P: Can be compressed using absolute paths!

-N: New dates (yy/mm/dd) will be packaged into the new file!

--exclude FILE: Do not package FILE during compression!

Example:

Example 1: Package all files in the entire/etc directory into/tmp/etc.tar

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

gzip, zcat command

[root@linux ~]# gzip [-cdt#] filename

[root@linux ~]# zcat filename.gz

Parameters:

-c: outputs compressed data to the screen, which can be processed through data stream redirection;

-d: parameters of decompression;

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

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

Example:

Example 1: Copy/etc/man.config to/tmp and compress it in gzip

[root@linux ~]# cd /tmp

[root@linux tmp]# cp /etc/man.config .

[root@linux tmp]# gzip man.config

#At this point man.config becomes man.config.gz !

Example 2: Read the contents of Example 1!

[root@linux tmp]# zcat man.config.gz

#The unzipped contents of man.config.gz will be displayed!!

Example 3: Unzip the file from Example 1

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

Example 4: Compress the man.config unpacked in Example 3 with the optimal compression ratio and keep the original file.

[root@linux tmp]# gzip -9 -c man.config > man.config.gz

bzip2, bzcat command

[root@linux ~]# bzip2 [-cdz] filename

[root@linux ~]# bzcat filename.bz2

Parameters:

-c: Output the compressed data to the screen!

-d: parameters of decompression

-z: parameters of compression

-#: Same as gzip, both are parameters for calculating compression ratio,-9 is the best,-1 is the fastest!

Example:

Example 1: compress/tmp/man.config as bzip2

[root@linux tmp]# bzip2 -z man.config

#At this point man.config becomes man.config.bz2 !

Example 2: Read the contents of Example 1!

[root@linux tmp]# bzcat man.config.bz2

#The contents of man.config.bz2 unzipped file will be displayed!!

Example 3: Unzip the file from Example 1

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

Example 4: Compress the man.config unpacked in Example 3 with the optimal compression ratio 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 used to decompress

-r: You can compress the files in the directory at the same time!

-c: output compressed data as standard output (output to screen)

Example:

Example 1: Copy/etc/man.config to/tmp and compress it

[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 Jul 27 11:43 man.config.Z

Example 2: Unpack the compressed file just now

[root@linux tmp]# compress -d man.config.Z

Example 3: Compress man.config into another file for backup

[root@linux tmp]# compress -c man.config > man.config.back.Z

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

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

-rw-r--r-- 1 root root 2605 Jul 27 11:46 man.config.back.Z

#This-c argument is interesting! He outputs the compression process data to the screen instead of writing it as

# file.Z file. Therefore, we can export the data to another file name by means of data stream redirection.

#About data flow redirection, we'll talk about it in detail in the bash shell!

DD command

[root@linux ~]# dd if="input_file" of="outptu_file" bs="block_size" \

count="number"

Parameters:

If: It's an input file, it can be a device!

of: output file oh ~ can also be a device;

bs: the size of a planned block, if not set, the default is 512 bytes

Count: How many BS?

Example:

Example 1: 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 25 14:16 /etc/passwd

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

#Take a closer look, my/etc/passwd file size is 1746 bytes, because I did not set bs,

#So the default is 512 bytes as a unit, so the above 3+1 means there are 3 complete

# 512 bytes, and another block less than 512 bytes!

#Actually, it feels like CP ~

Example 2: Backup MBR of/dev/hda

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

1+0 records in

1+0 records out

We know that the MBR of the entire hard drive is 512 bytes.

#is the first sector placed on the hard disk, so I can use this method to put

#All the information in MBR is recorded, it is really amazing! ^_^

Example 3: Backup the entire/dev/hda1 partition.

[root@linux ~]# dd if=/dev/hda1 of=/some/path/filenaem

This command is awesome! Back up the entire partition.

#The following of must not be in the directory of/dev/hda1 ~ otherwise, no matter how you read it, you can't finish reading ~

#This action is very effective, if you have to fill in the entire partition content again some day,

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

#If you want to backup the entire hard disk, just use Norton Ghost software.

#From disk to disk, hehe ~ use dd to do it ~ awesome!

cpio command

[root@linux ~]# cpio -covB > [file|device]

[root@linux ~]# cpio -icduv

Parameters:

-o: Copy data to a file or device

-i: copy data from a file or device into the system

-t: View the contents of a file or device created by cpio

-c: a newer portable format for storage

-v: allows saved in-process file names to be displayed on the screen

-B: Allow default Blocks to increase to 5120 bytes, default is 512 bytes !

The advantage of this is that large files can be stored faster (see i-nodes concept)

-d: Create directory automatically! Because cpio's contents may not be in the same directory,

If so, there will be problems in the reverse backup process! Add-d at this point,

You can automatically create the required directory!

-u: Automatically overwrite older files with newer ones!

Example:

Example 1: Write all the data on the system into the tape drive!

[root@linux ~]# find / -print | cpio -covB > /dev/st0

#Generally speaking, tape drives using SCSI interfaces are coded as/dev/st0!

Example 2: Check what files are on the tape drive.

[root@linux ~]# cpio -icdvt

[root@linux ~]# cpio -icdvt /tmp/content

#In the first action, the file name in the tape drive will be listed on the screen, and we can use the second action to

#Record all file names to/tmp/content file!

Example 3: Restore the data on the tape ~

[root@linux ~]# cpio -icduv

#Generally speaking, tape drives using SCSI interfaces are coded as/dev/st0!

Example 4: Backup all files under/etc to/root/etc. cpio!

[root@linux ~]# find /etc -type f | cpio -o > /root/etc.cpio

#This will enable backup ~ You can also send data as cpio -i

At this point, I believe that we have a deeper understanding of the "Linux compression packaging command use method," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report