What this section says:
- 9.1 The TAR command for file archiving and compression
- 9.2 Zip Management Compressed Files
- 9.3 Understanding GZIP-BZIP2-XZ Managing Compressed Files-file-sort viewing files
9.1 Tar command to archive and compress files 9.1.1 Archive and Compress files
The benefits of archiving and compressing files: saving hard disk resources and speeding file transfer rates
Parameters:
- -C Create File
- -x-extract [? Ekstr?kt] Extracting extract and restore files
- -V--verbose Show perform detailed procedures
- -F--file Specifying backup files
- -t--list lists which files are included in the package, does not understand the package, and views the contents of the package
- -C (uppercase)--directory Specify the decompression location
Example: Packaging for/boot/grub directory
[[email protected] ~]# tar -cvf grub.tar /boot/grub/ # tar的参数前可以不使用‘-’
Or:
[[email protected] ~]# tar cvf grub.tar /boot/grub/
Tar: Remove the Beginning "/" from the member name
/boot/grub//boot/grub/splash.xpm.gz[[email protected] ~]# ls gurb.tar[[email protected] ~]# tar xvf grub.tar #解压缩boot/grub/boot/grub/splash.xpm.gz[[email protected] ~]# ls boot #得到boot目录
Note: When you archive a file by using an absolute pathname, the previous/symbol in the path is removed from the file name by default. When this is extracted, it is extracted directly into the current directory. If you do not remove/compress, when unpacking, it is released directly by absolute path, overwriting the file of this path in the original system.
Example 1: Specifying the decompression location-C
[[email protected] ~]# tar xvf grub.tar.bz2 -C /opt/tar: 从成员名中删除开头的“/”/boot/grub//boot/grub/splash.xpm.gz[[email protected] ~]# ls /opt/boot
Example 2: Package two directories or directories + files into a single package:
[[email protected] ~]# mkdir back[[email protected] ~]# cp /etc/passwd back/[[email protected] ~]# tar -cvf back.tar /boot/grub back/ /etc/passwdtar: 从成员名中删除开头的“/”/boot/grub//boot/grub/splash.xpm.gzback/back/passwd/etc/passwd
Example 3: Do not understand the package and see what is in tar:
[[email protected] ~]# tar -tvf grub.tar # List all files in archive.tar verbosely.
Example 4: Contrast the effect of the plus V
[[email protected] ~]# tar -xf grub.tar [[email protected] ~]# tar -xvf grub.tar boot/grub/boot/grub/splash.xpm.gz
The Linux architect's high-paying entrance:
1. Learn God It Education official website: http://xuegod.ke.qq.com
2.1 Years veteran veteran of the industry MK:QQ2659153446
3. Join the Linux Technical Communication QQ Group:722287089, you can get the following benefits:
① regularly share free learning materials and videos (Tools + notes + expand Combat)
②10 senior veteran old birds online answer: Skills + Combat + Project sharing + high-paying employment
③ has the opportunity to receive 4 books of Linux cloud computing cluster architects free of charge
9.1.2 Tar archive + compression:
Syntax: Tar czvf newfile.tar.gz SOURCE
Common parameters:
- -Z,--gzip compressed by gzip extension: tar.gz
- -J: bz2 compression extension: tar.bz2
- -j: Compression extension in XZ mode: TAR.XZ
Example 1: Create a. tar.gz Package
[[email protected] ~]# tar cvf etc.tar /etc [[email protected] test]# tar zcvf etc.tar.gz /etc #归档,注意备份的名字后缀[[email protected] test]# tar zxvf etc.tar.gz #解压缩
Example 2: Create a. tar.bz2 Package
Example 3: Create a. TAR.XZ Package
[[email protected] ~]# tar -Jcvf etc.tar.xz /etc[[email protected] ~]# tar -xvf etc.tar.xz #tar.xz 这类包,解压缩
Or:
[[email protected] ~]# tar -Jxvf etc.tar.xz #
Compression ratio compared to three compression modes:
[[email protected] ~]# ll -h etc.tar*-rw-r--r-- 1 0 root 36M 5月 10 12:10 etc.tar-rw-r--r-- 1 0 root 9.6M 5月 10 12:14 etc.tar.bz2 #这个常用-rw-r--r-- 1 0 root 12M 5月 10 12:11 etc.tar.gz #这个常用-rw-r--r-- 1 0 root 7.7M 5月 10 12:16 etc.tar.xz #这个压缩比例最高,压缩的时间是最长
9.2 Zip Management Compressed Files
Zip Package Decompression command:
Zip is the compression program, unzip is the decompression program.
Example 1: Compressing a file:
Example 2: compressing all. jpg files into a zip package
[[email protected] ~]# zip all.zip *.jpg
Example 3: Compressing a directory
[[email protected] ~]# zip -r grub.zip /boot/grub #一般不用
Unzip:
[[email protected] ~]# unzip grub.zip[[email protected] ~]# unzip grub.zip -d /opt/ # -d 解压到指定的目标/opt
9.3 Understanding GZIP-BZIP2-XZ Managing Compressed Files-file-sort viewing files
We created a compressed tar archive, and the TAR command supports three different compression methods.
- Gzip compression speed is the fastest;
- BZIP2 compression generates a smaller file than gzip, but is less used than gzip wide;
- The XZ compression tool is relatively new, but provides the best compression ratio
The Linux architect's high-paying entrance:
1. Learn God It Education official website: http://xuegod.ke.qq.com
2.1 Years veteran veteran of the industry MK:QQ2659153446
3. Join the Linux Technical Communication QQ Group:722287089, you can get the following benefits:
① regularly share free learning materials and videos (Tools + notes + expand Combat)
②10 senior veteran old birds online answer: Skills + Combat + Project sharing + high-paying employment
③ has the opportunity to receive 4 books of Linux cloud computing cluster architects free of charge
9.3.1 Compression Tool
Compression tool: gzip bzip2 zip XZ
Common compression formats:. gz. bz2. xz. zip
Syntax format:
Compression
gzip 文件 ====》 gzip a.txt =====》 a.txt.gzbzip2 文件 ===》 bzip2 b.txt =====》 b.txt.bz2xz 文件 ===》xz c.txt ===》c.txt.xz[[email protected] ~]# mkdir xuegod[[email protected] ~]# touch xuegod/a.txt[[email protected] ~]# gzip xuegod/a.txt [[email protected] ~]# ls xuegod/a*xuegod/a.txt.gz
Note: The file can only be compressed, and the source files will disappear after compression, generally do not use.
(Bzip2,xz these two tools can leave the source file by adding the parameter-K)
[[email protected] ~]# cp /etc/passwd 1.txt[[email protected] ~]# bzip2 -k 1.txt[[email protected] ~]# ls 1.txt.bz2[[email protected] ~]# xz -k 1.txt[[email protected] ~]# ls 1.txt.xz
Extract:
- gzip-d file
- bzip2-d file-K reserved source file
- xz-d file or unxz file-K reserved source file
Cases:
[[email protected] mnt]# gzip -d 1.txt.bz2[[email protected] ~]# bzip2 -d 1.txt.bz2[[email protected] mnt]# xz -d 1.txt.bz2
9.3.2 File View Files
File command
- Effect: File-determine file Type #确定文件类型
- Usage: file/etc/passwd
Note: The Linux system does not identify file types according to the suffix name to view the file type with the files command.
[[email protected] ~]# file /etc/passwd/etc/passwd: ASCII text
9.3.3 sorting by certain rules view files
To view files:
[[email protected] ~]# ls -ltr 按时间排序 t 表示时间, -r 从小到大,不加r参数由大到小[[email protected] ~]# ls -lSr 按大小排序 -r 从小到大 [[email protected] ~]# ls -lSrh 按大小排序 -r 从小到大 ,加-h 参数,看大小,更清楚[[email protected] ~]# ls -lS 从大到小
View Catalog:
[[email protected] ~]# du -sh /etc 看某个目录大小
To view the partition size:
[[email protected] ~]# df -h 可以快速查看磁盘大小的存储空间
9.3.4 Sort: Commands to use when handling large amounts of data sort
Example 1: Sorting by default by alphabetic rules
[[email protected] ~]# cat /etc/passwd | sort | more
Example 2: Sorting by data
[[email protected] ~]# vim file2 #每行随意写一些数字
Example 2: Sorting by data, default from small to large
223231[[email protected] mnt]# sort -n file2 #-n默认从小到大 [[email protected] ~]# sort -r file2 #-r 反序排序(升序变成降序进行排序) 从大小到
Example 3: Support sorting by month
[[email protected] ~]# vim file3 #写入以下内容January MarchAprilFebruary[[email protected] ~]# sort -M file3AprilFebruaryJanuary March
Example 4: Combined use
- -t specifies a character to distinguish the key position
- -K followed by a number specifying the sort by the first column
-R reverse order (ascending to descending order)
[Email protected] ~]# sort-t ":"-k3-r/etc/passwd | More #按: Do the delimiter, in the 3rd column, which is the user uid, to sort from large to small
[Email protected] ~]# Du-h/etc | Sort-r | More #把etc目录下所有文件, sort by from big to small
The Linux architect's high-paying entrance:
1. Learn God It Education official website: http://xuegod.ke.qq.com
2.1 Years veteran veteran of the industry MK:QQ2659153446
3. Join the Linux Technical Communication QQ Group:722287089, you can get the following benefits:
① regularly share free learning materials and videos (Tools + notes + expand Combat)
②10 senior veteran old birds online answer: Skills + Combat + Project sharing + high-paying employment
③ has the opportunity to receive 4 books of Linux cloud computing cluster architects free of charge
Public Number:
MK Teacher Number:
Summarize:
- 9.1 The TAR command for file archiving and compression
- 9.2 Zip Management Compressed Files
- 9.3 Understanding GZIP-BZIP2-XZ Managing Compressed Files-file-sort viewing files
Archiving and compression of centos7.5-files