文件打包与解压缩

*.zip

zip 程序打包压缩的文件

*.tar tar 程序打包,未压缩的文件                                                 

ZIP压缩打包与解压

zip -r -q -o shiyanlou.zip /home/shiyanlou/Desktop

将目录 /home/shiyanlou/Desktop 打包成一个压缩文件shiyanlou.zip

参数详解:-r表示递归打包包含子目录的全部内容、-q安静模式不向屏幕输出信息、-o表示输出文件,需在其后紧跟打包输出文件名

解压:

shiyanlou.zip 解压到当前目录:

unzip shiyanlou.zip

将shiyanlou.zip解压到指定目录 加参数-d后接解压到的目的目录

unzip shiyanlou.zip -d ziptest

ziptest若没有则自动创建

若只是查看zip压缩包内容不解压 使用参数 -l

unzip -l shiyanlou.zip

tar压缩打包与解压

tar -P -cf shiyanlou.tar /home/shiyanlou/Desktop

-P (大写)保留绝对路径符,-c 表示创建一个 tar 包文件,-f 用于指定创建的文件名,注意文件名必须紧跟在 -f 参数之后

解压缩:需要提前创建目录 解包一个文件(-x 参数)到指定路径的已存在目录(-C 参数)

mkdir tardir
tar -xf shiyanlou.tar -C tardir

查看压缩包内容 使用参数  -t

tar -tf shiyanlou.tar

总结

  • zip:
  • 打包 :zip something.zip something (目录请加 -r 参数)
  • 解包:unzip something.zip
  • 指定路径:-d 参数
  • tar:
  • 打包:tar -cf something.tar something
  • 解包:tar -xf something.tar
  • 指定路径:-C 参数

猜你喜欢

转载自blog.csdn.net/m0_61843855/article/details/131628031