To add a directory prefix comfortably, use a different separator than /
in the --transform
argument, e.g. +
or ,
like in Andy's answer.
So, for a simpler case, you have a bunch of files in current directory, and you don't want to create a tarbomb.
tar czf logs_nightly.tar.gz --tranform 's+^+logs_nightly/+' *.log
The syntax is s+search+replace+
, and for ^
it simply matches the start of filename.
And now, just to answer the OP - well, you can avoid copying your whole directory to /tmp
by running:
mv $MYPATH $VERSION
tar cjf archive.tar.bz2 $VERSION
mv $VERSION $MYPATH
Alternatively:
ln $MYPATH $VERSION
tar cjf archive.tar.bz2 $VERSION
(hard link, avoids problems with symlinks)
The last two were included for entertainment value, I myself would stick to toro2k's answer.
Why copying it in the first place? Why not
tar cjf archive.tar.bz2 $MYPATH
? – Chewie – 2013-05-14T12:37:15.9202@Chewie he said, he want the $version as parent dir in archive. – Kent – 2013-05-14T12:39:36.353
Oh, I see it now. – Chewie – 2013-05-14T12:45:31.747