Can you have tar travel to a certain direct and then tar files relative to that directory? All while using one command (tar)?
For example instead of doing
cd /home/test/backups; tar zvPcf backup.tar.gz ../data/
I could do something like
tar -g '/home/test/backups/' zvPcf backup.tar.gz ../data/
The most common uses of the tar command are to create and extract a tar archive. To extract an archive, use the tar -xf command followed by the archive name, and to create a new one use tar -czf followed by the archive name and the files and directories you want to add to the archive.
see the -C option.
the tar man page gives this example :
tar -xjf foo.tar.bz2 -C bar/
extract bzipped foo.tar.bz2 after changing directory to bar
might be what you're looking for ...
Have you tried this:
tar zvPcf /home/test/backups/backup.tar.gz /home/test/backups/../data/
You could try:
tar zvPcf backup.tar.gz ../data/ -C '/home/test/backups/'
See tar(1) man page.
-C, --directory DIR
change to directory DIR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With