Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go to path and then tar?

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/
like image 794
ParoX Avatar asked Jul 02 '09 07:07

ParoX


People also ask

Which command will extract files tar to the current directory?

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.


4 Answers

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

like image 152
Sylvain Avatar answered Sep 28 '22 07:09

Sylvain


Have you tried this:

tar zvPcf /home/test/backups/backup.tar.gz /home/test/backups/../data/
like image 33
feihtthief Avatar answered Sep 28 '22 05:09

feihtthief


You could try:

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

like image 25
Florian Avatar answered Sep 28 '22 05:09

Florian


See tar(1) man page.

-C, --directory DIR
change to directory DIR

like image 33
Eugene Yokota Avatar answered Sep 28 '22 07:09

Eugene Yokota