LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Create a "relative path" tar-archive? (https://www.linuxquestions.org/questions/linux-newbie-8/create-a-relative-path-tar-archive-4175517308/)

wh33t 09-03-2014 05:09 PM

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.

AlucardZero 09-03-2014 05:38 PM

use relative paths when creating it

Code:

cd /
tar -zcf archive.tar.gz some/path/to/a/dir


wh33t 09-03-2014 05:40 PM

Quote:

Originally Posted by AlucardZero (Post 5231999)
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?

AlucardZero 09-03-2014 08:48 PM

write a script and have cron call the script

jpollard 09-04-2014 10:16 PM

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"

wh33t 09-04-2014 10:28 PM

Quote:

Originally Posted by jpollard (Post 5232574)
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!


All times are GMT -5. The time now is 08:20 PM.