I have a folder on Drive 1 called Music, and it is 100GB. I have a folder on Drive 2 called Music, and it is 116GB. It's the most updated version. How do I copy the Music folder from Drive 2 to Drive 1 without having to rewrite every single file?
4 Answers
The merge option will only show up if you are copying (rather than moving) the folder. Make sure you hold option while you drag the new folder to the location of the old folder. Alternatively, using ⌘+c to copy the new folder and ⌘+v to paste over the old folder should give you the option to merge the files.
-
This still seems to write over files that don't need to be rewritten. Using
rsync
instead– BRogersMar 9, 2016 at 2:44 -
Even if option to merge is available it sometimes does not work (just reports an error and do nothing) - especially in case of big folders as in your case. It's another reason why you should use rsync. Jan 13, 2017 at 11:17
This is a classic use case for rsync:
rsync -av /source-path/source-dir /destination-path
rsync will copy only new and changed files to the new location.
It is important to understand how a trailing slash on the source argument functions. If there is a trailing slash then the contents of /source-path/source-dir will be copied to destination-path. If there is no trailing slash then source-dir itself will be copied to the destination and its contents will be another level down in the destination hierarchy.
So if you want to replicate one path to another include the trailing slash as follows:
rsync -av /sourcepath/sourcedir/ /duplicatpath/sourcedir/
-
1Great catch! And if you're doing this from multiple drives (or anywhere on your computer) and don't want to type out the directories you can just drag a drive (external usb, or time capsule) or just a specific directory and have it add it to the command for you. Just drag the target location into terminal– BRogersMar 9, 2016 at 2:46
-
Man, thank you so much for suggesting the trailing slash. I've spent ours pondering why rsync -av ./foo/bar /vol1/foo/bar was copying over all existing files. Bloody slashes lol!!!– smingAug 11, 2016 at 14:31
UPDATE
First install coreutils first. Run brew install coreutils
. If you don't have brew
installed... switch back to windows!
Check that cp --version
outputs version cp (GNU coreutils) 8.^^
Then you will have the correct cp
version and the -u
flag will work.
Check the cp
command. Use man cp
and read the options.
You can do something like:
cp -r -u ~/source ~/destination
-R, -r, --recursive : copy directories recursively
-u, --update : copy only when the SOURCE file is newer than the destination file or when the destination file is missing
-p same as --preserve=mode,ownership,timestamps
-v --verbose : explain what is being done
So if you want to copy files from you Downloads/music folder to say your Music/new folder you would do something as:
cp -ruvp ~/Downloads/music/* ~/Music/new/
This would merge the contents of these two folders and if two files with the same name and path exist it would keep the newest one based on the timestamp.
-
1Are you sure the -u option works with the cp command in OSX? I'm getting the message "cp: illegal option -- u" in Sierra. It seems not all commands are the same as in Linux.– OMAJul 24, 2017 at 21:08
-
Try the cp --help command and see if the option is available. Or check the cp --version and make sure it is up to date. I am using : cp (GNU coreutils) 8.27– drew7721Jul 26, 2017 at 14:35
-
1Sadly, -u is not a valid flag for cp on OS X. It would be very convenient to have! Aug 26, 2017 at 21:27
-
-
1You can use the default
cp
. You don't need a special one. Usingcp -rnav source dest
orcp -rnpv source dest
achieves the same thing. So use the-n
flag instead of the invalid-u
flag. The-n
flag doesn't update modified files, but does add missing files.– Maytha8Dec 17, 2020 at 9:18
Not sure why the default Lion Merge button doesn't show up for me. But I ended up using ditto
. Found here: https://superuser.com/a/221599/102789
-
2BE CAREFUL! ditto does not keep newer files, it always overwrites destination with source. If source file is older, it will zap away the new file and replace with older file May 18, 2016 at 15:55
-
that's right - very important warning from FrancescoMM, use rsync Jan 13, 2017 at 11:18