views:

142

answers:

4

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/
+8  A: 

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 ...

Sylvain
+4  A: 

Have you tried this:

tar zvPcf /home/test/backups/backup.tar.gz /home/test/backups/../data/
feihtthief
+1  A: 

You could try:

tar zvPcf backup.tar.gz ../data/ -C '/home/test/backups/'

Florian
+1  A: 

See tar(1) man page.

-C, --directory DIR
change to directory DIR

eed3si9n