LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 10-15-2012, 12:32 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Rep: Reputation: 61
Unhappy 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.
 
Old 10-15-2012, 02:42 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it will store the path provided to it... show us the actual script.
 
Old 10-15-2012, 03:14 AM   #3
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,144

Rep: Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308Reputation: 2308
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.
 
Old 10-15-2012, 04:08 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
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
 
1 members found this post helpful.
Old 10-15-2012, 09:55 AM   #5
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by pan64 View Post
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
Perfect, thank you
 
Old 10-15-2012, 03:05 PM   #6
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
I can't seem to get this to work.

I'm currently doing

Quote:
$tar -C /home/wh33t/wwwroot/ -cf /home/wh33t/test.tar /home/wh33t/wwwroot/
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?
 
Old 10-15-2012, 03:46 PM   #7
JaseP
Senior Member
 
Registered: Jun 2002
Location: Eastern PA, USA
Distribution: K/Ubuntu 18.04-14.04, Scientific Linux 6.3-6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,802

Rep: Reputation: 157Reputation: 157
Uhm,... you put your directories in the path,... I never have to tar stuff up,... but try using ~/wwroot rather than your actual path...
 
Old 10-15-2012, 04:07 PM   #8
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by JaseP View Post
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.
 
Old 10-15-2012, 08:36 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
It looks like -C should do what you want http://linux.die.net/man/1/tar, but as above, you could just cd to the target dir first.
 
Old 10-15-2012, 08:46 PM   #10
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by chrism01 View Post
It looks like -C should do what you want http://linux.die.net/man/1/tar, but as above, you could just cd to the target dir first.
Can a script CD on it's own? Does that -C switch work for you? If so please copy and paste it to me so I know I've got the order correct.
 
Old 10-15-2012, 09:09 PM   #11
JaseP
Senior Member
 
Registered: Jun 2002
Location: Eastern PA, USA
Distribution: K/Ubuntu 18.04-14.04, Scientific Linux 6.3-6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,802

Rep: Reputation: 157Reputation: 157
Quote:
Originally Posted by wh33t View Post
Can a script CD on it's own? ...
Yes. Scripts can be amazingly complex.
 
Old 10-15-2012, 09:12 PM   #12
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by JaseP View Post
Yes. Scripts can be amazingly complex.
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?
 
Old 10-16-2012, 12:15 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 10-16-2012, 01:34 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
Quote:
Originally Posted by wh33t View Post
I can't seem to get this to work.

I'm currently doing



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 .
 
1 members found this post helpful.
Old 10-16-2012, 01:44 AM   #15
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 921

Original Poster
Rep: Reputation: 61
Quote:
Originally Posted by pan64 View Post
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?

Last edited by wh33t; 10-16-2012 at 01:49 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change of suffix format on "split" tar archive files scramble64 Linux - Software 2 11-24-2011 05:41 AM
"tar -xzf" error: "tar.child died with signal 13" vlsi Linux - General 4 05-26-2009 02:04 AM
Is ".gz" archive file considered "World-Readable"? NightSky Linux - Newbie 4 12-06-2007 05:21 PM
How to use "tar" to include./ on the path of the files jcbermu Linux - General 1 06-20-2007 07:20 AM
Samba: "homes" share, cannot create directories, can create files Herg Linux - Software 1 09-14-2006 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration