Automated Removal of Duplicate Folders (and contents of same) [Linux or Windows]

I have a number of folders and files on a Linux box that have been duplicated in a particular manner. The first level of folders are user names. Under each user folder, there are multiple project folders. Unfortunately because of some wonky software that was in use before my time, some of those project folders have been duplicated as a new project folder under that project folder. Probably makes sense if I give an example:

/root/John Doe/Project Alpha/Project Alpha

Files within /root/John Doe/Project Alpha/ are for the most part identical to those in /root/John Doe/Project Alpha/Project Alpha, but sometimes there are minor variations. The second project subfolder is however always identically named as the higher level project subfolder (including case).

What I'd like to do is simple in concept but apparently trickier in execution: Just delete the second subfolder and all of its contents, so that I'm left with /root/John Doe/Project Alpha and the files in that folder. There are tens of thousands of these project folders, so I was hoping to find a way to automate that deletion, preferably with a way to preview what will be deleted before committing.

Also, just in case someone feels this might be a duplicate, I have reviewed a number of prior posts, including this one and this one and have looked into a number of different tools referenced in those posts, including fdupes, AllDup and Duplicate Cleaner. Rather frustratingly, none of those are able to do what I've described above.

These folders and files are on a Ubuntu box that also be accessed from a Windows through Samba, so either Linux or Windows solutions could work.

If anyone has any suggestions on how I might be able to accomplish the above, or just point me in the right direction, I'd be most grateful.


Solution 1:

The fdupes tools is excelent for this task. Install It on your Linux box and have fun.

sudo apt install fdupes
fdupes -r folder1 folder2 # to see duplicates files
fdupes -r -d folder1 folder2 # to remove duplicated files with a confirmation question.