0

I've made a mistake and copied +16000 dirs into the home dir of a website. Now the home dirs and the dirs copied are in the same tree. My problem is of course not to delete the dirs which were originaly on the home dir and only the copied dirs... And (important) there was perhaps same dir name in the home dir, so the 2 have fusionned!...

My idea is to list the difference between the dir and the home dir then use this file to make a bash delete script. But I can't find the right command to have the list.. I tryied this but with no success:

comm <(ls DIR1) <(ls DIR2)

Any idea please?

1 Answers1

0

You can make a list of the directories in a given directory with

find dir1 -maxdepth 1 -type d  | sort > sorted_list1

Make a list for each dir, sort them, then use the differences to decide what to do with each dir.

To get the directories that are common, do:

comm -12 sorted_list1 sorted_list2

To get the directories that are just in dir2 do:

comm -13 sorted_list1 sorted_list2
stark
  • 12,615
  • 3
  • 33
  • 50