Linux file and directory management
- 1. Common compression commands in Linux systems
- 1.`gzip` 、 `zcat` 、` able` 、 `zless` 、` scratch`
- 2.`bzip2`、`bzcat`、`bzmore`、`bzless`、`bzgrep`
- 3.`xz`、`xzcat`、`xzmore`、`xzless`、`xzgrep`
- Second, the packaging command: ** tar **
- 3. Backup and Restore of XFS File System
- Four, CD writing tools
- 5. Other common compression and backup tools
- Six, key review
1. Common compression commands in Linux systems
Common compressed file extensions of Linux systems:
`*.Z` `compress`程序压缩的文件
`*.zip` `zip`程序压缩的文件
`*.gz` `gzip`程序压缩的文件
`.bz2` `bzip2`程序压缩的文件
`.xz` `xz`程序压缩的文件
`*.tar` `tar`程序打包的文件,并且没有被压缩过
`.tar.gz` `tar`程序打包的文件,并且经过`gzip2`的压缩
`.tar.bz2``tar`程序打包的文件,并且经过`bzip2`的压缩
`.tar.xz` `tar`程序打包的文件,并且经过`xz`的压缩
Linux is the most common compression command gzip
, bzip
and the latest xz
, while others have been out of fashion.
tar
Many files can be packaged as a file, but it does not have a compression function. In the GUN plan, the whole tar
and compression functions are combined to provide users with powerful compression and packaging functions.
The following introduces these basic compression commands
1.gzip
、zcat
、zmore
、zless
、zgrep
gzip
The compressed file created is *.gz
, let's take a look at the usage of this command
gzip [-cdtv] 文件名
zcat 文件名.gz
#选项与参数
-c:将压缩的数据输出到屏幕上,可通过数据流重定向来处理
-d:解压缩的参数
-t:可以用来检验一个压缩文件的一致性,看看文件是否有误
-v:可以显示出原文件/压缩文件的压缩比等信息
-#:#为数字的意思,-1最快,-9最慢,但是压缩比最好,默认是-6
Example 1: Find /etc
the file with the largest capacity below (without subdirectories), copy it /tmp
, and then gzip
compress it
[External link image transfer failed. The source site may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly ( img-mBKuiQ2L-1586345579555) (C: \ Users \ lee \ AppData \ Roaming \ Typora \ typora-user-images \ 1586260798861.png)]
[External chain image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-iLiEIxOy-1586345579557) (C: \ Users \ lee \ AppData \ Roaming \ Typora \ typora-user-images \ 1586261384080.png)]
When using gzip
compression, the original file will be compressed as a .gz
suffix by default , and the source file will no longer exist.
Example 2: Because it services
is a text file, you can read the contents of the previous compressed file
#`zcat`,`zmore`,`zless`可以读取文本文件
zcat services.gz
[External chain image transfer failed. The source site may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-VGTq2yIM-1586345579558) (C: \ Users \ lee \ AppData \ Roaming \ Typora \ typora-user-images \ 1586309435582.png)]
2.bzip2
、bzcat
、bzmore
、bzless
、bzgrep
bzip2
The usage is the gzip
same, except that the extension has been .gz
changed to .bz2
provide the best compression ratio
3.xz
、xzcat
、xzmore
、xzless
、xzgrep
xz
Higher compression ratio
`xz` [-dtlkc#] 文件名
`xcat` 文件名.xz
#选项与参数
-d 解压缩
-t 测试压缩文件的完整性
-l 列出压缩文件的相关信息
-k 保留原本的文件不删除
-c 将数据在屏幕上输出
-# 压缩比参数
xz -l services.xz #列出压缩前后的容量
xz -d services.xz #解压缩
xz -k services #保留原文件的文件名,并进一步压缩文件
Remarks : When I first started using the xz
command, I found that this command was not installed, so it was installed again, and the system did not bring the xz
command
Second, the packaging command: tar
tar
You can package multiple directories or files in the Linux system into one large file. Can also gzip
, bzip2
, xz
support, compress the files at the same time.
tar [-z|-j|-J] [cv] [-f 待建立的新文件名] filename... <==打包与压缩
tar [-z|-j|-J] [tv] [-f 既有的tar文件名] <===查看文件名
tar [-z|-j|-J] [xv] [-f 既有的tar文件名] [-C 目录] <===解压缩
#选项与参数
-c: 建立打包文件,可以搭配-v来查看打包过程中的文件名(filename)
-t: 查看打包文件的内容包含哪些文件,重点在查看[文件名]
-x: 解包或解压缩的功能,可以搭配-C(大写)在特定目录解压
-z: 通过`gzip`的支持进行压缩/解压缩,此文件名最好为*.tar.gz
-j: 通过`bzip`的支持进行压缩/解压缩,此文件名最好为*.tar.bz2
-J: 通过`xz`的支持进行压缩/解压缩,此时文件名最好为*.tar.xz。
-v:在压缩/解压缩的过程中,将正在处理的文件名显示处理
-f filename:-f 后面要立刻接要被处理的文件名
-C 目录:在特定目录解压,需要这个参数
The simplest use tar
:
压缩:tar -jcv -f filename.tar.bz2 [需要被压缩的文件或目录]
查询:tar -jtv -f filename.tar.bz2
解压:tar -jxv -f filename.tar.bz2 -C [需要解压的目录]
Let's test a few commonly used tar
methods
- Use the
tar
-z, -j, -J parameters to back up the/etc
directory
time tar -jpcv -f /root/etc.tar.bz2 /etc
time tar -jpcv -f /root/etc.tar.bz2 /etc
time tar -Jpcv -f /root/etc.tar.xz /etc
[External chain image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-6QosxuqE-1586345579558) (C: \ Users \ lee \ AppData \ Roaming \ Typora \ typora-user-images \ 1586325048104.png)]
3. Backup and Restore of XFS File System
Not studying for now
1. XFS
File system backupxfsdump
2. xfs
File system restorexfsrestore
Four, CD writing tools
Not studying for now
5. Other common compression and backup tools
Not studying for now
Six, key review
- The advantage of compression is that it can reduce the waste of disk capacity. On the website, file compression technology can also be used to transfer data, thereby improving the utilization of website bandwidth.
- Extension of the compressed file are
*.gz
mostly:*.bz2
,*.xz
,*.tar
,*.tar.gz
,*.tar.bz2
, ,*.tar.xz
tar
Can be used for file packaging, and can supportgzip
,bzip
,xz
compression- Compression: tar -Jcv -f filename.tar.xz The name of the file or directory to be compressed
- Query: tar -Jtv -f filename.tar.xz
and can supportgzip
,bzip
,xz
compression - Compression: tar -Jcv -f filename.tar.xz The name of the file or directory to be compressed
- Query: tar -Jtv -f filename.tar.xz
- Unzip: tar -Jxv -f filename.tar.xz -C need to unzip the directory