go to path and then tar?
-
21-08-2019 - |
Question
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/
Solution
Have you tried this:
tar zvPcf /home/test/backups/backup.tar.gz /home/test/backups/../data/
OTHER TIPS
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 ...
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow