0

Is there any way to set a different target directory structure than the orignial directory structure the tar archive was created from without creating it by hand?

For example, I have many files in a directory structure like this:

~/yyyy/mm/dd/hh/mm/*.*

Organized by when the file was received. I already create a tar archive without preserving the directory structure above for a whole day's worth of files (I have a small script that loops thru every minute of every hour and appends to a single tar archive). I would like to specify to tar to extract the archive to directory structure like this:

~/yyyymmdd

Seems simple enough as I could create the yyyymmdd directory by hand and just extract my archive into it, but I give this tar archive to a different system (which I have no control over) that relies on this tar archive being extracted to a yyyymmdd directory and the yyyy/mm/dd/hh/mm/*.* directory structure gives me performance gains because its organized. Also, I cannot change the original directory structure or waste system resources creating the desired target directory structure before creating the tar archive.

Is there a simple way extract a tar archive under a directory it was never in in the first place?

  • I don't. I apologize; I should have been more specific. The tar archive must be extracted just like this: tar xf archive.tar and produce a directory yyyymmdd/ with all the files in it. I will take a look at --strip-components and transform. – Jeff Hall Oct 14 '14 at 20:47
0

If you have this structure

/home/yyyy/mm/dd/hh/mm/
├── dir1
│   ├── file4
│   └── file5
├── dir2
│   └── file6
├── file1
├── file2
└── file3

and you want this structure

/home/yyyymmdd/
├── dir1
│   ├── file4
│   └── file5
├── dir2
│   └── file6
├── file1
├── file2
└── file3

Create:

tar -cvf /tmp/archive.tar /home/yyyy/mm/dd/hh/mm/

Extract:

tar --strip-components=6 -C /home/yyyymmdd/ -xvf /tmp/archive.tar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.