I have a large file foo.tar.xz
that contains a lot (say 200000) of files. I figured out that this archive contains some (around 5000) files I don't want. I don't have sufficient disk space to decompress the whole thing onto my disk; additionally, I fear attributes / rights might get lost if I do so. I have enough space to host two copies of the compressed archive though. Is there a tool to remove some of the files from the archive (specified with a regex on the filename) on-the-fly, i.e. without unpacking the archive into individual files?
Remove files from tar archive
tar
Best Answer
GNU tar has a
--delete
option that works with archives too nowadays.Use it like this, for example:
Beware: It will most likely not work on any kind of magnetic tape medium. But
tar
has no problems working in a pipe, so you can just use a temporary tar file and overwrite the tape with that afterwards. It also won't work on compressed files, so you would need to uncompress the file.Also, the operation will be rather slow in any case, due to the (by design) packed linear nature of tar archives.