Linux文件打包与解压缩
zip压缩打包程序
- 使用zip打包文件夹
其中shiyanlou:~/ $ zip -r -q -o shiyanlou.zip /home/shiyanlou/Desktop shiyanlou:~/ $ du -h shiyanlou.zip 12K shiyanlou.zip shiyanlou:~/ $ file shiyanlou.zip shiyanlou.zip: Zip archive data, at least v1.0 to extract-r表示递归打包包含子目录的全部内容,-q参数表示为安静模式,-o表示输出文件,需在其后紧跟打包输出文件名 - 设置压缩级别为 9 和 1(9 最大,1 最小),重新打包:
注意:这里只能使用绝对路径,否则不起作用zip -r -9 -q -o shiyanlou_9.zip /home/shiyanlou/Desktop -x ~/*.zip zip -r -1 -q -o shiyanlou_1.zip /home/shiyanlou/Desktop -x ~/*.zip - 创建加密zip包
zip -r -e -o shiyanlou_encryption.zip /home/shiyanlou/Desktop
使用unzip命令解压缩zip文件
- 解压到当前目录
unzip shiyanlou.zip - 使用安静模式,将文件解压到指定目录:
unzip -q shiyanlou.zip -d ziptest - 只查看压缩包的内容:
unzip -l shiyanlou.zip - 使用
-O参数指定编码类型:unzip -O GBK 中文压缩文件.zip
tar打包工具
- 创建一个tar包
cd /home/shiyanlou tar -P -cf shiyanlou.tar /home/shiyanlou/Desktop其中
-P保留绝对路径符,-c表示创建一个 tar 包文件,-f用于指定创建的文件名,注意文件名必须紧跟在-f参数之后,比如不能写成tar -fc shiyanlou.tar,可以写成tar -f shiyanlou.tar -c ~。你还可以加上-v参数以可视的的方式输出打包的文件 - 解包一个文件(
-x参数)到指定路径的已存在目录(-C参数):mkdir tardir tar -xf shiyanlou.tar -C tardir - 只查看不解包文件
-t参数:tar -tf shiyanlou.tar - 在创建 tar 文件的基础上添加
-z参数,使用gzip来压缩文件:tar -czf shiyanlou.tar.gz /home/shiyanlou/Desktop - 解压
*.tar.gz文件:tar -xzf shiyanlou.tar.gz - 使用其他压缩工具
压缩文件格式 参数 *.tar.gz-z*.tar.xz-J*tar.bz2-j