Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merging subdirectories with the same name

Perhaps I am mistaken, but I did not see a satisfactory answer for this question yet.

I have two directories which contain ~100 subdirectories. Within the directories, each subdirectory has the same name(s).

For example the first directory will have subdir1, subdir2, subdir3 and the second directory will have subdir1 subdir2, subdir3.

Within each subdirectory are files that need to all end up in one of the two subdirectories.

So basically I need a way of matching the identical subdirectory names and adding the files from one into the other. So that all the files from directory1/subdir1 and directory2/subdir1 end up in the same place.

There are too many files to make doing this manually very practical.

Any help would be much appreciated.

like image 623
user2472414 Avatar asked Oct 14 '25 08:10

user2472414


1 Answers

Why not just

cp -r source/ target/

Or, maybe

for name in subdir1 subdir2 subdir3; do cp -r */"$name"/; done

Add -v to see what gets copied. -u for "updates only"

like image 178
sehe Avatar answered Oct 16 '25 22:10

sehe