How do I delete a single file from a tar.gz archive

后端 未结 5 1984
花落未央
花落未央 2021-02-19 01:58

I have a huge tarbell archive with an excessively large or corrupt error_log that causes the archive to hang when attempting to extract it. Is there a way to remove this from th

5条回答
  •  走了就别回头了
    2021-02-19 02:22

    I did that in tree steps. Hopefully will help others in the future.

    gzip -d file.tar.gz
    tar -f file.tar --delete folder1/file1.txt --delete folder2/file2.txt
    gzip -9 file.tar
    

    If you have multiple files use this. But the archives them must have all the files you want to delete, or tar will give a error.

    for f in *.tar.gz
    do
            echo "Processing file $f"
            gzip -d "$f"
            tar -f "${f%.*}" --delete folder1/file1.txt --delete folder2/file2.txt
            gzip -9 "${f%.*}"
    done
    

提交回复
热议问题