LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-03-2014, 06:09 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 671

Rep: Reputation: 46
Question Create a "relative path" tar-archive?


For lack of actually knowing what I'm asking, let me explain.

When I do

Code:
tar -zcf archive.tar.gz /some/path/to/a/dir
When I go into the archive I see that it has preserved the absolute path of the directory structure. The archive actually contains
/some/path/to/a/dir and then files.

How can I make is so the root of the archive is the actual directory I'm archiving.

I suppose another way of saying this would be: How can I not archive the parent directories.
 
Old 09-03-2014, 06:38 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
use relative paths when creating it

Code:
cd /
tar -zcf archive.tar.gz some/path/to/a/dir
 
1 members found this post helpful.
Old 09-03-2014, 06:40 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 671

Original Poster
Rep: Reputation: 46
Quote:
Originally Posted by AlucardZero View Post
use relative paths when creating it

Code:
cd /
tar -zcf archive.tar.gz some/path/to/a/dir
How would I do that if this command is going to be run from a cron script?
 
Old 09-03-2014, 09:48 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
write a script and have cron call the script
 
Old 09-04-2014, 11:16 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
You can also use the -C option to first change to the directory, then specify the files.

Such as "tar -C /some/path/to/a/dir -zcf <full path to>/archive.tar.gz ."

If you wanted the "dir" to be part of the archive, then use "tar -C /some/path/to/a/ -zcf <full path to>/archive.tar.gz dir"
 
1 members found this post helpful.
Old 09-04-2014, 11:28 PM   #6
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 671

Original Poster
Rep: Reputation: 46
Quote:
Originally Posted by jpollard View Post
You can also use the -C option to first change to the directory, then specify the files.

Such as "tar -C /some/path/to/a/dir -zcf <full path to>/archive.tar.gz ."

If you wanted the "dir" to be part of the archive, then use "tar -C /some/path/to/a/ -zcf <full path to>/archive.tar.gz dir"
Thank you. That's what I needed!
 
  


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
"Not found in archive" error when extracting a list of specific files with tar oxEz Linux - General 8 03-02-2016 01:40 AM
Why does "tar" create the path directories to my target in the archive? wh33t Linux - Software 16 10-16-2012 02:52 AM
Change of suffix format on "split" tar archive files scramble64 Linux - Software 2 11-24-2011 06:41 AM
How to use "tar" to include./ on the path of the files jcbermu Linux - General 1 06-20-2007 08:20 AM
TAR Archive file - need relative path cmd0a0 Linux - Software 2 10-19-2005 03:57 PM


All times are GMT -5. The time now is 05:17 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