压缩工具:gzip、bzip2、rar、7zip、libzip2、xz
1.1:zip 压缩文件名 (text.zip)要被压缩的名字
[root@localhost test]# zip test1.zip test1.txt
adding: test1.txt (stored 0%)
[root@localhost test]# ls test1*
test1.txt test1.zip
1.2:把test2添加到test1.zip中
[root@localhost test]# zip -m test1.zip text2.txt
1.3: 把test2从test1.zip中删除
[root@localhost test]# zip -d test1.zip test2.txt
1.4:除了test10以外将所有.txt/压缩
[root@localhost test]# zip test.zip*.txt -x test10.txt
1.5:zip -r 递归压缩(将当前目录连同目录下文件一起压缩)
[root@localhost test]# zip -r dir1.zip dir1/
adding: dir1/ (stored 0%)
adding: dir1/fstab (deflated 50%)
[root@localhost test]# ls dir*
dir1.zip
dir1:
fstab
2.1:unzip解压文件
[root@localhost test]# unzip test1.zip
2.2:将压缩文件在指定目录下解压缩
[root@localhost test]# unzip test1.zip -d dir1
Archive: test1.zip
extracting: dir1/test1.txt
extracting: dir1/test2.txt
2.3:unzip -v test1.zip 不解压,查看压缩内容
1.1:gzip 被压缩文件名,压缩后,源文件不保留
[root@localhost test]# gzip test1.txt
[root@localhost test]# ls test1*
test1.txt.gz test1.zip
1.2:gzip -r 目录 压缩了目录下的所有内容。
[root@localhost test]# gzip -r dir1/
1.3:gzip -c test2.txt > test2.txt.gz 压缩,保留源文件
[root@localhost test]# gzip -c test2.txt > test2.txt.gz
[root@localhost test]# ls test2*
test2.txt test2.txt.gz
2.1:gunzip .解压文件至原路径
[root@localhost test]# gunzip test1.txt.gz
[root@localhost test]# ls test1*
test1.txt test1.zip
2.2: 解压至指定路径
[root@localhost test]# gunzip -c test2.txt.gz > /tmp/test.txt
2.3:.解压目录下的压缩文件
[root@localhost test]# gunzip -r dir1
[root@localhost test]# ls dir1
fstab test1.txt test2.txt
gunzip 和 gzip -d 等价
不解压查看
[root@localhost test1]# zless test2.txt.gz
1.1:bzip2 被压缩的文件名 ,压缩后,源文件不保留
[root@localhost test]# bzip2 test1.txt
[root@localhost test]# ls test1*
test1.txt.bz2 test1.zip
1.2:压缩,保留源文件
[root@localhost test]# bzip2 -c test2.txt > test2.txt.bz2
[root@localhost test]# ls test2*
test2.txt test2.txt.bz2 test2.txt.gz
2.1:将test2.txt.bz2解压缩
[root@localhost test]# bunzip2 test2.txt.bz2
bunzip2 和 bzip -d 等价
不解压查看
[root@localhost test1]# bzcat test5.txt.bz2
1.1:xz 被压缩的文件名,压缩后,源文件不保留
[root@localhost test]# xz test2.txt
[root@localhost test]# ls test2*
test2.txt.bz2 test2.txt.gz test2.txt.xz
1.2:查看压缩后的文件内容
[root@localhost test]# xzcat test2.txt.xz
1.3:压缩目录下文件
[root@localhost test]# xz dir1/*
[root@localhost test]# ls dir1
fstab.xz test1.txt.xz test2.txt.xz
2.1:解压缩
[root@localhost test]# unxz test1.txt.xz
2.2:解压目录下文件
[root@localhost test]# xz -d dir1/*
[root@localhost test]# ls dir1
fstab test1.txt test2.txt
xz -d 等价于 unxz