压缩命令
原创...大约 2 分钟
tar
市面上有非常多的压缩格式
zip
格式:Linux、Windows、MacOS 常用rar
:Windows 系统常用7zip
:Windows 系统常用tar
:Linux、MacOS 常用gzip
:Linux、MacOS 常用
Linux 和 Mac 系统常用有 2 种压缩格式,后缀名分别是:
.tar
,称之为 tarball,归档文件,仅将文件封装成一个.tar 文件,未压缩文件体积.gz
,也常见为.tar.gz,使用 gzip 算法进行压缩,从而大幅减小压缩后的文件体积
针对这两种格式,使用 tar 命令均可以进行压缩和解压缩的操作
tar [选项] [压缩文件] [被压缩的文件1,被压缩的文件2,被压缩的文件3...]
参数
-c
,创建压缩文件,用于压缩模式-v
,显示压缩、解压过程,用于查看进度-x
,解压模式-f
,要创建的文件,或要解压的文件-z
,gzip 模式,不使用-z 就是普通的 tarball 格式-C
,选择解压的目的地,用于解压模式
压缩
# 将1.txt 2.txt 3.txt 压缩到test.tar文件内
tar -cvf test.tar 1.txt 2.txt 3.txt
# 将1.txt 2.txt 3.txt 压缩到test.tar.gz文件内,使用gzip模式
tar -zcvf test.tar.gz 1.txt 2.txt 3.txt
解压缩
# 解压test.tar,将文件解压至当前目录
tar -xvf test.tar
# 解压test.tar,将文件解压至当前目录
tar -xvf test.tar -C /home/bz
# 以Gzip模式解压test.tar.gz,将文件解压至指定目录
tar -zxvf test.tar -C /home/bz
zip 与 unzip
zip 压缩
安装
sudo apt install zip
在 Linux 中,可以使用 zip 命令,压缩文件为 zip 压缩包
zip [选项] [压缩的文件名] [被压缩的文件1,被压缩的文件2,被压缩的文件3...]
参数
-r
,递归压缩
# 将a.txt b.txt c.txt 压缩到test.zip文件内
zip test.zip a.txt b.txt c.txt
# 将test文件夹和a.txt文件,压缩到test.zip文件内
zip -r test.zip test a.txt
unzip 解压缩
安装
sudo apt install unzip
在 Linux 中,可以使用 unzip 命令进行解压缩
参数
-d
,指定要解压到哪个位置
# 将test.zip解压到当前目录
unzip test.zip
# 将test.zip解压到指定文件夹内
unzip test.zip -d /opt
Powered by Waline v2.15.7