tar压缩工具

tar 本身为一个打包工具,可以把目录打包成一个文件,它的好处是它把所有文件整合成一个大文件整体,方便拷贝或者移动。

语法:tar [-zjxcvfpP] filename tar 命令有多个选项

“-z” : 同时用gzip压缩

“-j” : 同时用bzip2压缩

“-x” : 解包或者解压缩

“-t” : 查看tar包里面的文件

“-c” : 建立一个tar包或者压缩文件包

“-v” : 可视化

“-f” : 后面跟文件名,压缩时跟 “-f 文件名”,意思是压缩后的文件名为filename, 解压时跟 “-f 文件名”,意思是解压filename. 请注意,如果是多个参数组合的情况下带有 “-f”,请把 “-f” 写到最后面。

“-p” : 使用原文件的属性,压缩前什么属性压缩后还什么属性。(不常用)

“-P” : 可以使用绝对路径。(不常用)

--exclude filename : 在打包或者压缩时,不要将filename文件包括在内。(不常用)

打包的同时使用gzip压缩

tar命令非常好用的一个功能就是可以在打包的时候直接压缩,它支持gzip压缩和bzip2压缩。

[root@wen test]# mkdir test1018
[root@wen test]# touch test1018/test1.txt
[root@wen test]# echo "hello world" >test1018/test1.txt
[root@wen test]# tar -zcvf test1018.tar.gz test1018
test1018/
test1018/test1.txt
[root@wen test]# ls
test1018.tar.gz

“-zxvf” 用来解压.tar.gz的压缩包

[root@wen test]# rm -fr test1018
[root@wen test]# tar -zxvf test1018.tar.gz
test1018/
test1018/test1.txt
[root@wen test]# ls
test1018    test1018.tar.gz

 

相关文章:

  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2021-10-20
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-04-25
  • 2021-11-05
相关资源
相似解决方案