Linux中,向.tar.gz/.gz文件中添加一个文件,如何做?
迷茫
迷茫 2017-04-17 15:30:03
0
3
915

描述问题

需求: 对.zip .gz .tar.gz文件添加一个/几个新文件进去

在Windows上,操作极其简单,借助WinRAR,学习成本为0

在Linux上, 我

  1. 先是man tar man gzip

  2. 搜索 update append (gzip的搜索,直接没有, 关键词不对?)

  3. 然而没有找到支持压缩文件的选项(仅仅是对归档文件的支持)

注意到我需要:

  1. .zip .gz .tar.gz

  2. 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了

  1. append file to .tar.gz

  2. append file to .gz

  3. append dir to .tar.gz

附:
不成熟的吐槽

Linux是不是把事情搞复杂了?
还是我搜索/探索姿势不对? 
为啥有时候在Win上极其简单的一件事情,到了Linux上就要上升到折腾地步?  (得到一种莫名其妙的自我感动? )
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
PHPzhong
tar: Cannot update compressed archives

This error actually explains the problem - the compressed 'package' cannot be updated. Therefore, a feasible way is to first decompress tar.gz into tar, then update, and finally recompress (you can write a script).

Regarding ‘an extremely simple thing on Win’, it’s just because the software on Win is usually better packaged and the process of “decompression-update-compression” is hidden. Which one is better depends on the specific situation. As the questioner said, the learning cost of winrar is zero, but the disadvantage is that it is not programmable (it may also be because I am ignorant). Just imagine, if there are a large number of compressed packages that need to be updated every day, do you need to find someone to click on them in winrar?

PHPzhong

As far as we know, compressed files cannot be appended.
Can I append it to the tar file first and then compress it?
tar -rvf ttt.tar aaa.txt

黄舟

If you only use tar and gzip, .tar.gz seems to have to be decompressed first and then compressed...

By the way, aren’t we using the same Google? Why I found a solution:

http://unix.stackexchange.com...

It is mentioned that you can use FUSE or tarfs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!