I want to know if there is better way to rename a file from inside a .tar.bz2 file, without unpacking it and repacking the entire archive.
Asked
Active
Viewed 1,545 times
1
-
3It *might* be possible to rename a file inside a tar file. The bigger issue, however, is the bz2 compression. Perhaps it is possible to mount compressed files? (But something still has to decompress/compress it.) – Sep 11 '12 at 17:01
-
1See http://unix.stackexchange.com/questions/26105/rename-directory-inside-of-a-tar-archive – Sep 11 '12 at 17:03
1 Answers
1
bzip2 performs stream compression on the entire stream produced by tar. It has no notion of files, and as such the only way to find a file in a tar.bzip2 archive is to decompress the bzip2 until the point where the file appears. Removing the file and creating a new tar.bz2 archive would require creating a new tar file.
You may be able to reuse the beginning of the original tar.bz2 archive if you write a special-purpose cache to avoid recompression while decompressing the archive, but you will surely have to recompress the rest of the archive.
If your problem is disk space, you may try to perform the entire decompression and compression online via pipes, i.e.
bzcat original.tar.bz2 | command_to_rename_inside_tar | bzip2 > result.tar.bz2

epsalon
- 2,294
- 12
- 19