I'm .taring some files with the path example/super_user/Output.*.

The resulting .tar looks like this:

+ example
    + super_user
          - Output.zip
          - Output.xml
          - Output.txt

But I want the file to be like the following:

- Output.zip
- Output.xml
- Output.txt

Do you know how I can achieve this while still being in another directory?

link|improve this question

feedback

3 Answers

up vote 4 down vote accepted

tar will preserve the file and folder structure so I don't think there's any way to instruct tar to flatten the hierarchy at creation time.

One workaround is to temporarily change directory, create the tar, then go back - a quick example below:

cd example/super_user && tar -cvf ../../result.tar Output.* && cd ../..
link|improve this answer
feedback

If those are the entire contents of the tarball then you can use GNU tar's --strip-components option to remove the 2 levels before the files.

link|improve this answer
I've only got the option --strip-path but using it won't change anything. – New Talk Apr 18 '11 at 7:12
feedback

If the directory 'example' is at the root of the filesystem here's another way:

tar -C /example/super_user -cvf result.tar .

this will change directory to your the point that you want to do the tar. The caveat is that if there are any subdirectories under /example/super_user, the directory structure will be will be preserved for these sub-directories.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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