I'm trying to merge two directory trees that have many common elements but also each have elements that are only present in one of the two trees. The main issue I am having is that when mv
encounters two sub-directories with the same relative paths it either keeps the source (with -f
) or the destination (with -n
) but I can't make it take the union of both sub-directories. I could of course use rsync
with --remove-source-files
but this will actually copy the data and then delete the old files as opposed to a true move. The two directory trees contain several hundred GB of data and are both on same partition so I would love to do a true move if possible for the sake of time.
Right now I have find * -type file -exec mv -n {} /destination/{}
but this only moves files from the source to the destination when the target directory already exists. I can preface this command with something like mv -n * /destination/
but this only brings over the top level directories. Is there any way to do this in a single line? I could always write a script to check if the directory exists before copying the file but this seems like such a basic task, it seems like there should be an easier way.
prename
anywhere so I went with G-Man solution. The files should be the same on both sides so it doesn't matter if it overwrites or now. – Reed Espinosa Aug 29 '14 at 00:00prename
. – Graeme Aug 29 '14 at 05:23