Why does "tar" create the path directories to my target in the archive?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why does "tar" create the path directories to my target in the archive?
Hey LQ,
I've got a back up script doing some rsync and tar bz2 to create an archive. So far this is working out pretty good but whenever I go to unpack the archive I always get these extra directories in the archive which I'm not expecting.
The target tar directory is something like /home/wh33t/backupdirectory/ and in the archive there will be a /home, a /home/wh33t, and a /home/wh33t/backupdirectory/ which I am not expecting to see there.
I just want to see the files and directories at the root of the backupdirectory/.
I know there is probably a command switch for this but I'm not even sure what this is referred to.
it sounds like you should do a cd to the backup directory immediately before the tar command.
If you grok 'info tar' in great detail you'll probably find a switch for skipping levels of leading directories on extraction. Mind you, I'm sure that won;t be worth the effort involved. I find 'info tar' a good way of confusing what I already know about tar and a bad way of learning anything.
tar has an option -C <dir> to go to a location before doing the job, so probably you need something like:
tar -C /home/wh33t <your flags to create an archive> backupdirectory
tar has an option -C <dir> to go to a location before doing the job, so probably you need something like:
tar -C /home/wh33t <your flags to create an archive> backupdirectory
and it's still creating /home, /home/wh33t, and /home/wh33t/wwwroot/ in the tarchive...
I've tried this command in a few different orders as well to no avail. I've tried doing the -C switch before -cf, after the -cf and after the target directory. Any ideas?
Uhm,... you put your directories in the path,... I never have to tar stuff up,... but try using ~/wwroot rather than your actual path...
I'm not sure what you mean by "you put your directories int he path," as the tarchive still get's created as expected. As I mentioned in my post I have tried putting the -C switch before and after the parameters and it came out the same. Using ~/wwwroot may or may not work, but it's not useful to me as I need the script to be portable to other systems and I won't always have the luxury of target directories being in the home dir.
I've really got to learn how to script. That's what the majority of linux is isn't? Got any good links for scripting? It's BASH script I want to learn right?
and it's still creating /home, /home/wh33t, and /home/wh33t/wwwroot/ in the tarchive...
I've tried this command in a few different orders as well to no avail. I've tried doing the -C switch before -cf, after the -cf and after the target directory. Any ideas?
You need to use relative path:
tar -C /home/wh33t/wwwroot cf /home/wh33t/test.tar .
You need to use relative path:
tar -C /home/wh33t/wwwroot cf /home/wh33t/test.tar .
Ooooh I see!
Ok well I tried it out and it mostly worked. I'm my tar archive I don't have any /home or /home/wh33t but I do have .. and . and my directories in there are prefixed with .\, so my directories in the root of the tarchive are like .\dir1, .\dir2. Is that to be expected? Is that what happens on your machine?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.