2021SC@SDUSC
File compression
Have you ever had the trouble that files are too large to be copied by U SB flash disk, and have you ever had to back up some important data, which is too large and consumes a lot of disk space? At this time, the "file compression" technology can come in handy.
Since the number we record is 1, considering the so-called binary of the computer, 1 will occupy one bit on the far right, and the other seven bits will be automatically filled with 0. Therefore, the remaining seven bit space is null, and compression is to fill these null values temporarily to save space. When we use them, expand these null values, This is the most commonly used compression technology.
Another compression technique is also very interesting. It records duplicate data statistically. For example, if your data is "111..." and there are 100 1s in total, the compression technique will record "100 1s" instead of 100 1s. This can also reduce the capacity of file records.
Here's a little bit of knowledge. Some assembly language algorithms can compress a movie to a few KB, and there can also be sound. Isn't it amazing? This is also the strength of assembly language.
This is because Linux supports many compression commands, and the compression technologies used by different commands are different. Of course, they may not be able to exchange compressed / decompressed files with each other. Therefore, when you download a compressed package, you naturally need to know what kind of compression command the file is made from, so that it can be compared with decompression, that is, Although the attributes of Linux files are basically not absolutely related to files, in order to distinguish these files, the compression technology is used, so the extended name appears.
File backup
To be honest, backup is the Savior waiting for rescue when the system is damaged, because when you need to reinstall the system, the quality of backup will affect the progress of your system recovery, but what we want to know first is why the system is damaged? Is it artificial or how? In fact, the system may cause errors due to unexpected damage. What is unexpected damage? This is because the system may be due to unexpected hardware damage, such as hard disk failure, or software problems, including human improper operation or other unknown factors. Let's talk about system damage and how to backup it.
Experiment 8: Backup compression
1. Experimental purpose
1) Master the principle and use of the command line of backup and compression in the file system under Ubuntu system
2. Experimental contents
This experiment is mainly to master the use of backup compression under Linux system, mainly including the following contents:
Part 8 (backup compression):
1.zipinfo command – view compressed file information
2.zip command – zip file
3.gzip command – compress and unzip files
4.unzip command – unzip the zip file
5.unarj command – unzip the. arj file
3. Experimental environment
Raspberry pie 4B, Ubuntu 21.10. The programming environment of the experiment is Terminal terminal program
4. Experimental steps
1.zipinfo command – view compressed file information
(1) Grammar
zipinfo [parameters]
(2) Function
The zipinfo command lists compressed file information. Execute the zipinfo command to know the details of the zip compressed file.
(3) Parameters
-1 Only file names are listed. -2 Effect and assignment of this parameter-1″Parameters are similar, but can be matched "-h","-t"And "-z"Parameter usage. -h Only the file names of compressed files are listed. -l Effect and assignment of this parameter-m"Parameters are similar, but the size of the original file is listed instead of the compression ratio of each file. -m Effect and assignment of this parameter-s"The parameters are similar, but the compression ratio of each file is listed. -M If the information content exceeds one picture, a similar method is adopted more Lists information in the form of instructions. -s "Execute with similar" ls -l"The effect of the directive lists the contents of the compressed file. -t Only the number of files contained in the compressed file, the file size and compression ratio before and after compression are listed. -T List the date and time of each file in the compressed file in the order of year, month, day, hour, minute and second. -v The information of each file in the compressed file is displayed in detail. -x<Template style> Does not list information for eligible files. -z If the compressed file contains comments, the comments are displayed.
(4) Instance
Display compressed file information:
[root@localhost ~]# zipinfo cp.zip Archive: cp.zip 486 bytes 4 files -rw-r--r-- 2.3 unx 0 bx stor 24-May-10 18:54 a.c -rw-r--r-- 2.3 unx 0 bx stor 24-May-10 18:54 b.c -rw-r--r-- 2.3 unx 0 bx stor 24-May-10 18:54 c.c -rw-r--r-- 2.3 unx 0 bx stor 24-May-10 18:54 e.c 4 files, 0 bytes uncompressed, 0 bytes compressed: 0.0% [root@localhost ~]#
2.zip command – zip file
(1) Grammar
zip [parameters] [file]
(2) Function
The zip command can be used to decompress files or package files. Zip is a widely used compression program. After the files are compressed, compressed files with ". Zip" extension will be generated. Since various systems support zip compression format, it can be used in general to a certain extent.
(3) Parameters
[root@localhost ~]# zip --help Command syntax:[ zip/unzip [option] File or directory ] -r #Recursive compression, compressed together with subdirectories -S #Contains system and hidden files -v #Display instruction execution process -q #Instruction execution is not displayed
(4) Instance
By using zip -r -v The command compresses the entire contents of the / etc / Directory:
[root@localhost ~]# zip -r -v lyshark.zip /etc/ [root@localhost ~]# ls -lh total 12M -rw-r--r--. 1 root root 12M Nov 16 09:46 lyshark.zi
3.gzip command – compress and unzip files
(1) Grammar
gzip [parameters]
(2) Function
Gzip command is a command often used in Linux system to compress and decompress files. It is convenient and easy to use. Its extended name is GZ. Gzip can not only compress large and less used files to save disk space, but also form a popular compressed file format in Linux operating system together with tar command, According to statistics, gzip command has a compression ratio of 60% ~ 70% for text files. Reducing the file size has two obvious advantages: one is to reduce the storage space, and the other is to reduce the transmission time when transmitting files through the network.
Note: if a large file is changed into a small file through the compression algorithm, the gzip command cannot directly compress the directory, so you need to package it into a file with tar, and then call gzip for compression
(3) Parameters
-d # Add compressed files -v # Displays the process of instruction execution -l # Lists the content messages of the compressed file -c # Output content to standard output without changing the original file -r # Recursively compress all files in the directory -t # Test to check whether the compressed file is complete
(4) Instance
(1) Compression instance: compress a file by using the gzip -rv command:
[root@localhost ~]# ls -lh total 944K -rwxr-xr-x. 1 root root 942K Sep 26 2017 bash [root@localhost ~]# gzip -rv bash bash: 51.2% -- replaced with bash.gz [root@localhost ~]# ls -lh total 460K -rwxr-xr-x. 1 root root 460K Sep 26 2017 bash.gz
(2) Query instance: query a file by using gzip -l/zcat -l command:
[root@localhost ~]# gzip -l bash.gz compressed uncompressed ratio uncompressed_name 470300 964544 51.2% bash [root@localhost ~]# zcat -l bash.gz compressed uncompressed ratio uncompressed_name 470300 964544 51.2% bash
(3) Unzip instance: unzip a file by using the gzip -dv / zcat command:
[root@localhost ~]# ls -lh total 460K -rwxr-xr-x. 1 root root 460K Sep 26 2017 bash.gz [root@localhost ~]# gzip -dv bash.gz bash.gz: 51.2% -- replaced with bash [root@localhost ~]# zcat -d bash.gz >bash_zcat [root@localhost ~]# ls -lh total 2.1M -rw-r--r--. 1 root root 942K Nov 16 06:56 bash -rw-r--r--. 1 root root 942K Nov 16 06:56 bash.zcat -rwxr-xr-x. 1 root root 460K Sep 26 2017 bash.gz
4.unzip command – unzip the zip file
(1) Grammar
unzip [parameters] [file]
(2) Function
Unzip command can unzip files in ZIP format compressed by zip command or other compression software
(3) Parameters
-c The decompressed results are displayed on the screen, and the characters are converted appropriately. -f Update existing files. -l Displays the files contained in the compressed file. -p And-c Parameters are similar, and the decompressed results will be displayed on the screen, but no conversion will be performed. -t Check whether the compressed file is correct. -u And-f Parameters are similar, but in addition to updating existing files, other files in the compressed file will also be decompressed to the directory. -v Displays detailed information when executing yes. -z Only the note text of the compressed file is displayed. -a Perform the necessary character conversion on the text file. -b Do not convert characters to text files. -C File names in compressed files are case sensitive. -j The original directory path in the compressed file is not processed. -L Change all file names in the compressed file to lowercase. -M Send output results to more Program processing. -n Do not overwrite the original file during decompression. -o You don't have to ask the user first, unzip Overwrite the original file after execution. -P<password> use zip Password options for. -q No information is displayed during execution. -s Converts white space characters in file names to underscore characters. -V retain VMS File version information for. -X When decompressing, the original file is saved back at the same time UID/GID. [.zip file] appoint.zip Compressed files. [file] Specify to process.zip Which files in the compressed file. -d<catalogue> Specify the directory where the file will be stored after decompression. -x<file> Specify not to process.zip Which files in the compressed file. -Z unzip -Z Equal to execution zipinfo Instructions.
(4) Instance
Query the files in a compressed package by using the unzip -l command:
[root@localhost ~]# unzip -l lyshark.zip
Unzip the file to the specified directory by using the unzip -d command:
[root@localhost ~]# unzip lyshark.zip -d /tmp/ [root@localhost ~]# ls -lh /tmp/ total 12K drwxr-xr-x. 84 root root 8.0K Nov 6 11:02 etc
5.unarj command – unzip the. arj file
(1) Grammar
unarj [parameters] [. arj compressed file]
(2) Function
The unarj command is used to extract. arj files. Unarj is the compression program for. arj compressed files.
(3) Parameters
-e decompression .arj File. -l Displays the files contained in the compressed file. -t Check whether the compressed file is correct. -x Keep the original path when decompressing.
(4) Instance
Unzip the. arj file:
[root@localhost ~]# unarj -e test.arj
Display the files contained in the compressed file:
[root@localhost ~]# unarj -l test.arj
Check whether the compressed file is correct:
[root@localhost ~]# unarj -t test.arj
Keep the original path during decompression:
[root@localhost ~]# unarj -x test.arj
Extract the file to the current path:
[root@localhost ~]# unarj -ex test.arj