LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2007, 03:14 PM   #1
kmack1023
LQ Newbie
 
Registered: Apr 2005
Location: Detroit, MI
Distribution: Ubuntu (home), SLES (work)
Posts: 27

Rep: Reputation: 15
tar help


I know this is going to come off as a stupid simple question, but I've, honestly, been looking for a solution for about 20 or 30 minutes to no avail...

how do I tar a directory, so that I can choose where the archives highest level directory is? Does that make sense? Say I want to back up all the music I have in a folder /home/me/music/a/, but I want the highest level of the archive to be "/a/"?

I know just changing to that directory and running it from there (a) will yield the results I want, but I want to do it in a crontab...do I need to do a script to change directories first and then issue the "tar -zcf backup.tgz /a/" command?

probably way too long of a post for such a simple question...my apologies...
 
Old 08-21-2007, 03:39 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,532

Rep: Reputation: 210Reputation: 210Reputation: 210
Run this:

cd /home/me/music/ && tar -zcf backup.tgz a/

When you extract backup.tgz, you will have the "a" directory and all its contents. Note the "&&" in the above line is a way of stringing commands without writing a script but you could do the same with a simple bash script if you prefer and run that from cron.
 
Old 08-21-2007, 08:39 PM   #3
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,191

Rep: Reputation: 105Reputation: 105
More specifically, && means run the second command only if the first command succeeds. So, if you make a mistake in the first command and try to cd into a non-existent directory, it won't waste time trying to do the second. You can use this construct in a script as well.
 
Old 08-21-2007, 09:39 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
You can also use the -C option to change to the required directory:
Code:
tar -zcf backup.tgz -C /home/me/music a
 
Old 08-22-2007, 08:43 AM   #5
kmack1023
LQ Newbie
 
Registered: Apr 2005
Location: Detroit, MI
Distribution: Ubuntu (home), SLES (work)
Posts: 27

Original Poster
Rep: Reputation: 15
excellent! that's the info I was hoping for! I tried the -C option before and I was having problems with it... I'll try all of the suggestions to help me better understand tar and cron...thanks for the replies!
 
Old 08-22-2007, 08:51 AM   #6
kmack1023
LQ Newbie
 
Registered: Apr 2005
Location: Detroit, MI
Distribution: Ubuntu (home), SLES (work)
Posts: 27

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by gilead View Post
You can also use the -C option to change to the required directory:
Code:
tar -zcf backup.tgz -C /home/me/music a
It won't archive with that code....is there a / missing somewhere or something like that?
 
Old 08-22-2007, 02:38 PM   #7
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
No, that's the correct syntax - I just ran it here again and it worked. Can you try it in verbose mode (tar -zvcf) and post any errors you get?
 
Old 08-23-2007, 07:49 AM   #8
kmack1023
LQ Newbie
 
Registered: Apr 2005
Location: Detroit, MI
Distribution: Ubuntu (home), SLES (work)
Posts: 27

Original Poster
Rep: Reputation: 15
bah! I could've sworn I did that earlier and it didn't work...thanks for the help! It worked wonderfully!
 
  


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
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 02:48 AM
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 10:55 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
tar | ssh (tar > .tar) syntax issues EarlMosier Linux - Software 6 12-21-2006 12:28 AM
Diferance between rpm, tar, tar.gz, scr.tar, etc mobassir Linux - General 12 08-21-2003 06:30 AM


All times are GMT -5. The time now is 07:43 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration