26
1
I am attempting to create a script that can compress files with a certain extension in a number of directories into a single tar-ball. Currently what I have in the script file is:
find "$rootDir" -name '*doc' -exec tar rvf docs.tar {} \;
Where $rootDir
is the base path to search.
This is fine except the paths are absolute in the tar file. I would prefer the paths to be relative to $rootDir
. How would I go about doing this?
Example of current tar -tf docs.tar
where $rootDir
is /home/username/test
output:
home/username/test/subdir/test.doc
home/username/test/second.doc
What I desire the output to be:
./subdir/test.doc
./second.doc
3Or just use
cd $rootDir
andcd -
(at least inbash
).( cd $rootDir ; find ... )
would also be possible, i.e. doing everything in a subshell. – Daniel Beck – 2013-03-25T19:04:18.210Thanks. Worked brilliantly. Didn't realise linux had pushd/popd. – Shane – 2009-11-12T10:37:39.910