Deleting files after adding to tar archive

后端 未结 4 579
夕颜
夕颜 2021-02-02 05:40

Can GNU tar add many files to an archive, deleting each one as it is added?

This is useful when there is not enough disk space to hold both the entire tar archive and th

4条回答
  •  臣服心动
    2021-02-02 06:19

    I had a task - archive files and then remove into OS installed "tar" without GNU-options.

    Method:

    Use "xargs"

    Suppose, we are have a directory with files.
    Need move all files, over the week into tar and remove it.
    I do one archive (arc.tar) and added files to it. (You can create new archive every try)

    Solution:

    find ./ -mtime +7 | xargs -I % sh -c 'tar -rf arc.tar % ; rm -f %'
    

提交回复
热议问题