PDA

View Full Version : Using tar to compress a file in a script, how to specify the directory tree?



jucas_lo
March 6th, 2009, 12:15 PM
Hi! I need to do make a bash script, and i have to create a tar file of a directory. Now I have two small problems that if I manage to resolve, would make my life a lot easier:

1) I need to tar the directory test/conf. So i do:


tar -uf conf.tar test/conf/

In the tar created i get a directory test and under this I get the folder conf (test/conf). So is there a way to tell tar to create only a conf folder in the tarfile (i.e. instead of test/conf just conf) without manually changing dirs?. I tried:
tar -uf conf.tar testrel/conf/ -C testrel/conf/ but it didn't work

2) Can I change the name of the output folder when extracting ? for instance if I am extracting a tar in which there is only one folder called conf, can i tell tar to extract it with the name conf2???

I would really appreciate any suggestion!!!

thanks guys!

:popcorn:

dwhitney67
March 6th, 2009, 01:19 PM
tar -C test -cvf conf.tar conf

jucas_lo
March 6th, 2009, 01:58 PM
thanx

the_unforgiven
March 6th, 2009, 06:03 PM
Check out the --transform option from the tar manual:
http://www.gnu.org/software/tar/manual/tar.html#SEC108

This allows you to replace the names/paths of the files as they go in and out of the tarfile.
Pretty neat if you want to make the path to which it should be extracted different from which it was built.