Question

I have two directories structured as follows:

dir1/a/file1
dir1/a/b/file2
dir1/a/c/d/file3

and

dir2/a/file4
dir2/a/b/file5
dir2/a/c/d/file6

I want to copy all the files in the subdirectories under dir1 to dir2, but keep the files that are currently in dir2, in other words I want to resulting structure to look like:

dir2/a/file1
dir2/a/file4

dir2/a/b/file2
dir2/a/b/file5

dir2/a/c/d/file3
dir2/a/c/d/file6

Is there a simple way to do this using bash?

Était-ce utile?

La solution

You could start with

cd dir1 
cp -rpuv * ../dir2/

Before:

$ find dir2/
dir2/
dir2/a
dir2/a/file4
dir2/a/c
dir2/a/c/d
dir2/a/c/d/file6
dir2/a/b
dir2/a/b/file5

After:

$ find dir2/
dir2/
dir2/a
dir2/a/file1
dir2/a/file4
dir2/a/c
dir2/a/c/d
dir2/a/c/d/file3
dir2/a/c/d/file6
dir2/a/b
dir2/a/b/file2
dir2/a/b/file5

Note that -p preserves permissions, -v make copy verbose and -u only updates files (doing what the question suggests: keep the files already in dir2)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top