gzip和gunzip指令
gzip用户压缩,gunzip用于解压缩
gzip 文件
:把文件压缩成.gz
(原文件将会移除,不会保留原来的文件)
gunzip 文件.gz
:解压缩(不会保留压缩文件)
zip和unzip指令
zip用于压缩,unzip用于解压(项目打包常用)
zip [选项] XXX.zip 需要压缩的内容
:压缩文件和目录
unzip [选项] XXX.zip
:解压缩文件
zip选项:
-r
:递归压缩,即压缩目录(压缩目录不适用-r,压缩的内容为空)
unzip选项:
-d 目录
:指定解压缩的目录
tar指令
tar [选项] XXX.tar.gz 需要打包的内容
:打包后的文件是.tar.gz的文件
选项:
-c
:产生.tar打包文件
-v
:显示详细信息
-f
:指定压缩后的文件名
-z
:打包同时压缩
-x
:解压.tar文件
[root@localhost home]# tar zcvf hz.tar.gz hz/
hz/
hz/mydate.txt
hz/.local/
hz/.local/share/
hz/.local/share/flatpak/
hz/.local/share/flatpak/repo/
hz/.local/share/flatpak/repo/extensions/
hz/.local/share/flatpak/repo/state/
hz/.local/share/flatpak/repo/objects/
hz/.local/share/flatpak/repo/refs/
hz/.local/share/flatpak/repo/refs/remotes/
hz/.local/share/flatpak/repo/refs/heads/
hz/.local/share/flatpak/repo/refs/mirrors/
hz/.local/share/flatpak/repo/tmp/
hz/.local/share/flatpak/repo/tmp/cache/
hz/.local/share/flatpak/repo/config
hz/.local/share/flatpak/.changed
hz/test/
hz/test/test.txt
[root@localhost home]# ls -l
总用量 20
drwx------. 4 hz hz 4096 7月 21 22:35 hz
-rw-r--r--. 1 root root 6786 7月 21 22:52 hz.tar.gz
drwx------. 15 xh xh 4096 7月 13 23:11 xh
drwx------. 5 zhangwj mojiao 4096 7月 14 22:51 zhangwj
解压并指定目录(解压指定的目录事先需要存在,否则报错)
[root@localhost home]# tar -zxvf hz.tar.gz -C hz/
hz/
hz/mydate.txt
hz/.local/
hz/.local/share/
hz/.local/share/flatpak/
hz/.local/share/flatpak/repo/
hz/.local/share/flatpak/repo/extensions/
hz/.local/share/flatpak/repo/state/
hz/.local/share/flatpak/repo/objects/
hz/.local/share/flatpak/repo/refs/
hz/.local/share/flatpak/repo/refs/remotes/
hz/.local/share/flatpak/repo/refs/heads/
hz/.local/share/flatpak/repo/refs/mirrors/
hz/.local/share/flatpak/repo/tmp/
hz/.local/share/flatpak/repo/tmp/cache/
hz/.local/share/flatpak/repo/config
hz/.local/share/flatpak/.changed
hz/test/
hz/test/test.txt
[root@localhost home]# ls -l hz/hz/
总用量 24
-rw-r--r--. 1 root root 17589 7月 20 22:32 mydate.txt
drwxr-xr-x. 2 root root 4096 7月 21 22:30 test