Good morning,
I have a tar compressed archive tar.bzip2 (created using tar jcf
), which contains a file named data.txt (1).
On the other side, I have another file also named data.txt (2).
Is there a way to append file (2) to the end of file (1) without untar bz2 archive, append file and then tar it back again?
By the way, I already did the three steps, I'm asking just for curiosity (or 'out of curiosity'... not sure about this expression in English).
I've been looking for the right option, but I cannot find it out:
-r
option tells me 'abort', I guess because I tried to append a file which already exists in archive.-u
cannot update compressed archives, although I think it will only replace (1) by (2).-A
also tells me 'abort'. I'm not really sure what this option does. It seems to add the files in one archive to another existing archive. So it's not what I want.
I'm using GNU tar 1.15.1 over Linux.
Note:
I think I didn't explain it well enough, so I better use an example:
I have a file named data.tar.bz2 which contains a file named data.txt (1). Its contents could be
A
I have another file also named data.txt (2). Its contents could be
B
My purpose is that the file contained in data.tar.bz2 has both (1) and (2) file contents in one file named, of course, data.txt:
A
B
In other words do this using one command, without decompressing, untar, create temporal directories, etc...:
mkdir $tempDir
tar jxf data.tar.bz2 -C $tempDir
cat data.txt >> $tempDir/data.txt
tar jcf data.tar.bz2 -C $tempDir data.txt
rm -r $tempDir
Yes, I want to append, but -r
option won't work because, if I'm not wrong, it appends files to archive, but it does not append the contents of an existing file in the archive. Hope this clarifies... not sure at all xD
tar
? It doesn't seem so. Anyway, tar files are not designed to be manipulated in this way, you can stop trying, unfortunately. – wurtel Dec 17 '14 at 13:02-A
, you could have added the description with a statement that you don't understand that description, for example. It's always useful to give as much info as you can. No problem about your 1st comment BTW. I have never viewed tar archives as suitable for updating, use zip for that. Maybe you might have more success with non-compressed files (as I now see the answer below states). – wurtel Dec 17 '14 at 14:02