Walk the path and then the tar?

Can you attach tar to specific direct and then tar files relative to this directory? All using one command (tar)?

For example, instead of executing

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/
+5
source share
4 answers

Have you tried this:

tar zvPcf /home/test/backups/backup.tar.gz /home/test/backups/../data/
+4
source

see option -C.

The tar man page gives the following example:

   tar -xjf foo.tar.bz2 -C bar/
          extract bzipped foo.tar.bz2 after changing directory to bar

maybe what you are looking for ...

+8
source

:

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

+1

. tar (1) .

-C, --directory DIR
DIR

+1

All Articles