Merging two directory without copying the files

command linecpdirectory

Let's say I have as follows :

Folder A
    C1
        file a
    A2

Folder B
     C1
     B2
         file b
     B3

What I want is to merge these two folders, which would give me :

Folder C
    C1
    A2
    B2
    B3

Notice I didn't write file a and file b. I only want to merge the architecture. Each repository contains different files and I don't want them to be added to the merged directory. As a consequence, mv Folder\ A/* Folder\ B is not adequate.

Do you guys see a way to do so ?

Best Answer

Well, you could have find exec mkdir.

cd /A/
find -type d -exec mkdir -p /C/{} \;

Or if the structure is flat as shown in your example, without find

cd /A/
for dir in */
do
    mkdir -p /C/"$dir"
done

and in both cases the same again for cd /B/.

Related Question