需求: 对.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.gz 先解壓成 tar,然後再更新,最後再重新壓縮(可以寫個腳本)。
關於‘Win上極其簡單的一件事情’,只是因為 Win 上的軟體通常封裝的比較好而已,把“解壓-更新-壓縮”的過程隱藏起來了而已。這裡面孰優孰劣要看具體情況,winrar 如題主所說學習成本為零,但是缺點是不可不可編程(也可能是我孤陋寡聞)。試想,如果有每天有大量的壓縮包需要更新,那是不是要專門找個人在 winrar 裡點點呢?
目前所知,壓縮後的檔案是不可追加的。
可以先追加到tar文件,再壓縮也行吧?
tar -rvf ttt.tar aaa.txt
只用
tar
和gzip
的話,.tar.gz
好像只能先解壓縮再壓縮...話說難道我們用的google不是同一個?為啥我搜到了個解決方案:
http://unix.stackexchange.com...
裡面提到使用FUSE或tarfs就可以了。