需求: 对.zip
.gz
.tar.gz
文件添加一个/几个新文件进去
在Windows上,操作极其简单,借助WinRAR,学习成本为0
在Linux上, 我
先是man tar
man gzip
搜索 update
append
(gzip的搜索,直接没有, 关键词不对?)
然而没有找到支持压缩文件的选项(仅仅是对归档文件的支持)
注意到我需要:
.zip .gz .tar.gz
append/delete
因此有6个需求
解决方法是?
Linux(仅仅使用发行版内置命令, 不借助任何外部工具, 换句话来说: 命令大概是gzip tar ...这些) 仅仅使用bash命令行(无GUI)
查看man命令即可
man的一部分信息
-A, --catenate, --concatenate append tar files to an archive 是archive! -c, --create create a new archive -d, --diff, --compare find differences between archive and file system --delete delete from the archive (not on mag tapes!) -r, --append append files to the end of an archive -t, --list list the contents of an archive --test-label test the archive volume label and exit -u, --update only append files newer than copy in archive
上述选项,对.tar.gz使用时会报错 比如: tar rzv -f zipfile.tar.gz new-file tar: Cannot update compressed archives
Google了
append file to .tar.gz
append file to .gz
append dir to .tar.gz
附:
不成熟的吐槽
Linux是不是把事情搞复杂了? 还是我搜索/探索姿势不对? 为啥有时候在Win上极其简单的一件事情,到了Linux上就要上升到折腾地步? (得到一种莫名其妙的自我感动? )
只用tar
和gzip
的话,.tar.gz
好像只能先解压缩再压缩...
话说难道我们用的google不是同一个?为啥我搜到了个解决方案:
http://unix.stackexchange.com...
里面提到使用FUSE或者tarfs就可以了。
目前所知,压缩后的文件是不可追加的。
可以先追加到tar文件,再压缩也行吧?
tar -rvf ttt.tar aaa.txt
tar: Cannot update compressed archives
这个报错其实已经说明问题了--不能对压缩的’包‘进行更新操作。所以,可行的办法是将tar.gz 先解压成 tar,然后更新,最后重新压缩(可以写个脚本)。
关于‘Win上极其简单的一件事情’,只是因为 Win 上的软件通常封装的比较好而已,把“解压-更新-压缩”的过程隐藏起来了而已。这里面孰优孰劣要看具体情况,winrar 如题主所说学习成本为零,但是缺点是不可不可编程(也可能是我孤陋寡闻)。试想,如果有每天有大量的压缩包需要更新,那是不是要专门找个人在 winrar 里点点点呢?