压缩方式:zip gzip bzip2 xz 对应后缀名:.zip .gz .bz2 .xz 后缀名的作用:告诉用户使用哪种方式解压 1.zip和unzip zip是既可以归档又可以压缩的工具,可以用来压缩目录 ①使用zip压缩文件test1.txt,可以指定压缩比,最高为9 zip test1.zip test1.txt zip -9 test.zip test1.txt ②将当前目录dir1连同目录下的文件一起压缩 zip -r dir1.zip dir1/ ③向压缩文件text1.zip中添加text2.txt文件 zip -m test1.zip test2.txt ④删除压缩文件中的文件 zip -d test1.zip test2.txt ⑤压缩文件时排除某个文件 zip test.zip *.txt -x test1.txt ⑥解压文件 unzip test2.zip ⑦解压缩到指定目录 unzip test2.zip -d dir1 ⑧查看压缩文件目录但不解压文件 unzip -v test2.zip 2.gzip和gunzip gunzip = gzip -d ①使用gzip压缩文件 gzip test1.txt ②压缩目录下的文件 gzip -r dir1/ #注意:以上压缩之后原始文件会消失 ③压缩且保留源文件 gzip -c test2.txt > test2.txt.gz ④查看压缩文件内容 zcat test2.txt.gz ⑤解压文件 gzip -d test1.txt.gz gunzip test1.txt.gz ⑥“非标准”扩展名解压 gzip -cd test3.haha > test3 3.bzip2和bunzip2 ①使用bzip2压缩 bzip2 man.config ②采用最佳压缩比并保留原文件 bzip2 -9 -c man.config > man.config.bz2 ③解压缩 bzip2 -d man.config.bz2 bunzip2 man.config.bz2 ④查看压缩文件的内容 bzcat man.config.bz2 4.xz和unxz ①压缩文件 xz test1.txt ②压缩dir1目录下的文件 xz dir1/* ③查看压缩文件内容 xzcat test1.txt.xz ④解压缩 xz -d test1.txt.xz unxz test1.txt.xz 这几种压缩和解压缩方式使用的命令基本相同,这里不再详写 tar归档命令 tar打包时排除 --exclude=PATTERN 排除以PATTERN指定的文件 tar --exclude=*.gz ceshi8.tar.gz test5.txt ./dir1 -X,--exclude-from=FILE 排除FILE中列出的模式串