linux使用tar命令,Linux的tar命令使用简介

tar -xzvf .tar.gz -C dir 解压缩

tar -czvf.tar.gz file1 file2 dir 压缩

(1)创建

-f, --file=ARCHIVE     use archive file or device ARCHIVE :使用存档文件或设备档案(后面跟所要打包或解包的包名)

-v, --verbose      verbosely list files processed:详细显示

-c, --create      create a new archive :          建立新的归档文件

tar cvf applepen.tar apple pen

把apple pen这两个文件打包成一个文件applepen.tar,.tar是文件后缀。

记住-f后面先写打包的包名 applepen,后面是要打包的内容,apple和pen。

(2)压缩

-z, --gzip   ilter the archive through gzip:使用gzip压缩

可以调用gzip,bzip等压缩工具,对包进行压缩。gzip最常用,使用gzip即可,.gz为后缀。

(3)解包

-x, --extract, --get    extract files from an archive:解压(自动识别各种格式的压缩)

-C, --directory=DIR  change to directory DIR:加压到指定目录

tar xvf app/applepen.tar

-f后面跟所要加压的包即可

(4)查看

-t, --list     list the contents of an archive: 查看存档的内容列表

tar tvf applepen.tar

-t查看包里的内容,并不解压。

(5)追加

-r, --append      append files to the end of an archive:附加文件

tar rvf applepen.tar a1 a2

把a1、a2追加到已经打好的包里

(6)删除

--delete    delete from the archive (not on mag tapes!):删除包里的文件

tar --delete -vf applepen.tar a1 a2 a3

删除包里面的文件a1、a2、a3,没有的话会报错,注意名子要一样。

注意

不要用绝对路径,使用相对路径;

tar: Removing leading `/' from member names  (移除绝对路径的/)

如果带/,解压后可能覆盖原有文件。

不要在当前目录打包,在上级目录打包

tar: ./aaa.tar.gz: file is the archive; not dumped

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值