Linux常用压缩解压命令

为了便于传输或节省存储空间有时候文件是以压缩包的形式存在,因此就需要了解压缩与解压相关命令。

tar

语法:tar [参数] 包名.tar.gz 待打包的内容
作用:打包目录,压缩后的文件格式为.tar.gz
参数:
​ -c:create生成.tar打包文件
​ -x:extract解包.tar文件
​ -v:verbose显示详细信息
​ -f:file指定压缩后的文件名
​ -z:打包同时压缩
​ -C:解压到指定目录
举例:
压缩多个文件,将test.txt压缩为test.tar.gz

[root@ljh2020 test]#  tar -zcvf test.tar.gz test.txt 
test.txt
[root@ljh2020 test]# ll
total 10260
-rw-r--r-- 1 root root 10485760 May  9 22:00 10_file
-rw-r--r-- 1 root root     7877 Sep  3  2014 bd_logo1.png
drwxr-xr-x 2 root root     4096 May  9 22:42 test1.txt
-rw-r--r-- 1 root root      132 May  9 22:57 test.tar.gz

压缩目录

[root@ljh2020 ~]# tar -zcvf test.tar.gz test/
zip和unzip

语法:
​ 压缩:zip [参数] 包名.zip 待压缩内容
​ 解压:uzip 包名.zip
作用:压缩文件和目录,windows和linux通用且可以压缩目录并保留源文件
参数:
​ -r:recurse-paths递归压缩目录
举例:
压缩test.txt为test.zip

root@ljh2020 test]# zip test.zip test1.txt  
  adding: test1.txt/ (stored 0%)

解压test.zip

[root@ljh2020 test]# unzip test.zip 
Archive:  test.zip
gzip和gunzip

语法:
​ 压缩:gzip [参数] 文件
​ 解压:gzip [参数] 文件.gz
作用:
​ 压缩:压缩文件,只能将文件压缩为*.gz文件。只能压缩文件不能压缩目录,压缩解压后不保留原来的文件。对单个文件压缩
​ 解压:解压文件
​ 举例:
压缩文件

[root@ljh2020 test]# ll
total 10256
-rw-r--r-- 1 root root 10485760 May  9 22:00 10_file
-rw-r--r-- 1 root root     7877 Sep  3  2014 bd_logo1.png
drwxr-xr-x 2 root root     4096 May  9 22:42 test1.txt
-rw-r--r-- 1 root root       12 May  9 21:45 test.txt
[root@ljh2020 test]# gzip test.txt

解压文件

[root@ljh2020 test]# ll
total 10256
-rw-r--r-- 1 root root 10485760 May  9 22:00 10_file
-rw-r--r-- 1 root root     7877 Sep  3  2014 bd_logo1.png
drwxr-xr-x 2 root root     4096 May  9 22:42 test1.txt
-rw-r--r-- 1 root root       41 May  9 21:45 test.txt.gz
[root@ljh2020 test]# gunzip test.txt.gz
[root@ljh2020 test]# ll
total 10256
-rw-r--r-- 1 root root 10485760 May  9 22:00 10_file
-rw-r--r-- 1 root root     7877 Sep  3  2014 bd_logo1.png
drwxr-xr-x 2 root root     4096 May  9 22:42 test1.txt
-rw-r--r-- 1 root root       12 May  9 21:45 test.txt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值