Suppose I have:
dir_1
- file_a
- subdir_0
- file_b
- file_c
dir_2
- file_a
- subdir_0
- file_b
I want to copy over every file that exists in both directories to dir_2. In the above example, this would mean file_a
and subdir_0/file_b
.
What’s the easiest way to accomplish this in bash?
2
Answers
Using find and a shell loop:
Remove
echo
to actually copy the files.One
find/while/read
idea:This generates: