Linux file compression technology

Compression command

Common compressed file extensions

  • . tar: Tar program packages files without compression
  • .tar. GZ: Tar program package file, gzip compressed
  • .tar. Bz2: Tar program package file, bzip2 compression
  • .tar. xz: Tar program package file, compressed by xz
  • . GZ: gzip program zip file
  • . Z: compress program compresses files
  • . bz2: bzip2 program zip file
  • . XZ: XZ program zip file
  • . zip: zip program zip file

As mentioned before, file extensions under linux are useless. Compressed files have multiple extensions to support a variety of compression commands. gzip, bz2, zip, etc. are commonly used. At present, compress is not commonly used. The purpose of tar packaging files is to integrate multiple files into a single file to facilitate compression with one command

gzip

Gzip is the most widely used compression command, which can unlock compressed files such as compress, zip, gzip, etc

gzip [-cdtv#] filename
zcat filename.gz
-c : Output compressed data to screen
-d : decompression 
-t : Detect compressed file consistency(Are there any errors)
-v : Display original file/Compression ratio of compressed file
-# : #Refers to the number 1-9. 1 is the fastest and 9 has the highest compression ratio. The default is 6 

The files compressed by gzip command can be decompressed by WinRAR and 7zip software under windows system
decompression

gzip -d filename.gz
gupzip filename.gz

The zcat command can read the data of the compressed file and use the egrep command to find the keywords in the compressed file
In addition, the znew command is used to convert compress ed files to gzip format

bzip2

bz2 has a better compression ratio than gzip, and its usage is roughly the same, but when compressing large files, the compression time is significantly longer than gzip

bzip2 [-cdkzv#] filename
bzcat filename.bz2
-c : Output compressed data to screen
-d : decompression 
-k : Keep original file
-z : Compression parameters
-v : Display original file/Compression ratio of compressed file
-# : #Refers to the number 1-9. 1 is the fastest and 9 has the highest compression ratio. The default is 6 

xz

Bzip2 has a better compression ratio than gzip, and its usage is the same as the first two

xz [-dtlkc#] filename
xcat filename.xz
-d : decompression 
-t : Test compressed file integrity(Are there any errors)
-l : Lists information about compressed files
-k : Keep original file
-c : Compressed data output to screen
-# : #Refers to the number 1-9. 1 is the fastest and 9 has the highest compression ratio. The default is 6 

Packaging command tar

Tar packages multiple directories and files into a large file, and compresses the files through the support of gzip, bzip2 and XZ At present, WinRAR under Windows is also supported tar.gz format file decompression

tar -[zjJ] [cv] [-f filename.tar] filename # pack
tar -[zjJ] [tv] [-f filename.tar] # View file name
tar -[zjJ] [xv] [-f filename.tar] [-C directory] # Extract to directory

-c: Create package file
-t: View the file names contained in the packaged file
-x: decompression 
-z: Use after packing gzip compress
-j: Use after packing bzip2 compress
-J: Use after packing xz compress
-v: The packaging process displays the file name processed
-f filename: -f Followed by the file name to be processed
-C: Followed by the extracted directory
-p: Preserve the permissions and properties of backup data
-P: Keep absolute path, Allow backup data to contain a root directory
--exclude=FILE: Ignore files during packaging FILE

Examples of common commands

tar -jcv -f filename.tar.bz2 [filename|directory] # Packed and compressed with bzip2
tar -jtv -f filename.tar.bz2 # query
tar -jxv -f filename.tar.bz2 -C directory # Unzip bzip2 to directory

CD recording technology

Although USB external hard disk is usually used to back up data, the CD-ROM is still available, which is worth discussing CD-ROM writing

  1. Create data as an iso file with the mkisofs command
  2. Burn to disc with cdrecord command

mkisofs

mkisofs [-o image] [-Jrv] [-V vol] [-m file] Files to be backed up > -graft-point isodir=systemdir

-o: After image file name
-J: Generate compatibility Windows File name structure, And allow names up to 64 in length unicode character
-r: adopt Rock Ridge Generate support Unix/linux File data for
-v: Show creation process
-V vol: establish Volume
-m file: Exclude files file
-graft-point: Transplantation function

cdrecord

Since CentOS 7, the wodim command has been used for recording, but because it is compatible with the old version, cdrecord is still available. Wodim is linked to the cdrecord command

wodim --devices dev=/dev/sr0 # Query recorder bus location
wodim -v dev=/dev/sr0 blank=[fast|all] # Erase repeat read / write disk
wodim -v dev=/dev/sr0 -format # Format DVD+RW
wodim -v dev=/dev/sr0 [-data|speed=X|-eject|fs=Ym] file.iso

--devices: Scan the disk bus to find the recorder, Follow up equipment ATA Interface
-v: Display process
dev=/dev/sr0: Find the optical drive bus address
blank=[fast|all]: Erase rewritable CD/DVD-RW, fast For fast, all For complete
-format: format, But only for DVD+RW
-data: Specify data format
speed=X: Specify the recording speed
-eject: Recording is complete. Eject the disc
fs=Ym: The specified buffer size is Ym, The default is 4 m, Change according to actual parameters of recorder

Other compression / backup commands

dd

In addition to making files, dd is mainly used for backup

dd if="input_file" of="output_file" bs="block_size" count="number"

if: Entered file/equipment
of: Output file/equipment
bs: set up block size, The default is 512 B(One sector)
count: block Number of

cpio

cpio can back up any file, including the device

cpio -ovcB > [file|device] # backups
cpio -ivcdu < [file|device] # reduction
cpio -ivct < [file|device] # see

You need to use CPIO in combination with find to find files, such as backing up all files of / boot to / TMP / boot cpio

cd /
find boot | cpio -ocvB > /tmp/boot.cpio

decompression

cd /tmp
cpio -idvc < /tmp/boot.cpio

Keywords: Linux

Added by cgraz on Sat, 15 Jan 2022 17:35:31 +0200