[sclug] strip paths from file when tarring?

David Given dg at cowlark.com
Sat Mar 5 23:42:23 UTC 2005


John Stumbles wrote:
[...]
> tar cjf mytar.tbz2 foo/ bar/; cd long/path/to/; tar cjf mytar.tbz2 \
> logfile.log

There's always the pipe-tastic:

(tar cf - foo/ bar/ && (cd long/path/to/ && tar cf - logfile.log)) \
   | bzip2 -9vc > mytar.tar.bz2

You can't append compressed tar files, but you *can* append uncompressed 
ones --- as far as I can remember.

(Incidentally, as a matter of shell scripting style: if you use && to 
seperate commands instead of ; then if one command fails the whole thing 
will stop. e.g.:

cd / ; cd this/directory/doesnt/exist ; rm -rf .

...will do Bad Things. Using && will Not Do Bad Things.

-- 
David Given
dg at cowlark.com


More information about the Sclug mailing list