Search code examples
directoryextractarchive

How to extract archives with same folder structure so that folder contents are merged?


I want to be able to create 2 or more tar.gz (or other) archives that will have some overlapping directories, but not overlapping files. I would like to extract my 2 or more archives into the same working area and have the contents of overlapping directories overlaid or merged, rather than have a situation where I get 'Folder' and 'Folder (2)'

More detailed example:

arch_1.tar.gz contains the following

Project
   Documentation
       README_1.md
   Code
       app_xyz.c
       server_xyz.c

And arch_2.tar.gz contains this

Project
   Documentation
      README_2.md
   Code
      app_abc.c
      server_abc.c

Now I want to be able to extract the 2 example tar.gz archives from above and end up with this:

Project
   Documentation
      README_1.md
      README_2.md
   Code
      app_abc.c
      app_xyz.c
      server_abc.c
      server_xyz.c

But right now, when I test this, I get this (not desirable):

Project
   Documentation
      README_1.md
   Code
      app_xyz.c
      server_xyz.c
Project (2)
   Documentation
      README_2.md
   Code
      app_abc.c
      server_abc.c

Someone at work described this to me a while ago and it sounded great, but I haven't been able to implement it. Maybe it's just a matter of different options on the command line when I go do the extract.

In case it matters, I am using Windows 7 on 1 machine that will be creating the tar.gz files but the extraction will likely occur in Mint Linux (all other dev machines).


Solution

  • Use the command line tar utility rather than the default GUI option provided by your operating system.

    tar -xvf arch_1.tar.gz
    tar -xvf arch_2.tar.gz
    

    does exactly what I wanted to do.

    When I tried right-click > extract using Mint Linux it did not merge the folder contents.