0

Most q&a about tar either ask about grouping an entire directory into a tar, or single files matching a pattern (e.g. same extension), but I want to do a mix of both.

That is, if I have this dir structure:

SomeDir/someFile1.a
SomeDir/someFile2.b
SomeDir/someFile3.c
SomeDir/...
SomeDir/someFileN.xyz
fileInRoot.abc
OtherDir/someFile.xyz
OtherDir/theFile.f

I want to tar the SomeDir completely, and the single theFile.f alone, so that, when I decompress it in another server, I'm left with this dir structure:

SomeDir/someFile1.a
SomeDir/someFile2.b
SomeDir/someFile3.c
SomeDir/...
SomeDir/someFileN.xyz
OtherDir/theFile.f

Is this possible? Which flags to tar should I use?

  • 1
    try tar -cvf test.tar SomeDir OtherDir/theFile.f – Sundeep Jul 21 '16 at 4:33
2

If I'm understanding what you want correctly, you can simply pass directory/files names to tar.

 tar -cvf tarfile.tar SomeDir/ OtherDir/theFile.f

Upon extracting:

[user]$: ls
OtherDir  SomeDir  tarfile.tar

[user]$: tar -xf tarfile.tar

[user]$: ls SomeDir/
someFile1.a  someFile2.b  someFile3.c  someFileN.xyz

[user]$: ls OtherDir/
theFile.f
  • perfect thanks! can't upvote because I'm new :-S – user1623521 Jul 21 '16 at 4:45

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.