how to tar or zip two sibling folders and avoid an extra top level folder when extracting

TrekOnTV2017 asked:

I have a need to create a tar of two sibling folders and send it to a client for extraction on their Mac OS desktop by double-clicking it. yes, that’s a requirement of theirs.

so I go:

cd ~/Desktop
tar -cvf ~/Desktop/files.tar folder1 folder2
#folder1 and folder2 are sibling sub folders of ~/Desktop and contain additional files and sub folders

the problem is that when I (or the client) double click on files.tar (which initiates the extraction), it first creates a top level directory called files and only then the two sub folders (~/Desktop/files/folder1 and ~/Desktop/files/folder2) … rather than creating ~/Desktop/folder1 and ~/Desktop/folder2. This creates a problem for the client with path dependencies.

is there a way to force a creation of such a .tar or .zip that doesn’t create the top level folder first ? (with the name made up from its file name) and extracts the content directly to the current location ?


My answer:

Whatever GUI tool you’re using in OS X is doing that, not tar. If you actually use tar to extract the file, you will get the expected directory structure.

$ tar xvf files.tar

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.