Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAC : How to merge folder so that we only overwrite when source files is newer than destination files?

It seems like very basic command. However even after an hour of searching the solution, I still can't find something that works.

So I have two big folders (with many files and many subfolder, the mega back-up). I'd like to combine these two folders into one folder that contains only newer files. So I'm searching a way to overwrite files IF ONLY source file is newer than the destination file, or when the destination file does not exist.

I'm running Mac version 10.7.4. I'm open to installing new application and/or using terminal/bash command.

like image 793
Fleea Avatar asked Jan 13 '13 18:01

Fleea


1 Answers

In Gnu systems, use mv -u SOURCE DEST or cp -u SOURCE DEST to move or copy only when the SOURCE file is newer than the DEST file or when the destination file is missing.

Note that in OS X, mv and cp don't support the -u option. However, rsync has a -u option and it is supported on OS X. For example:

rsync -aru SOURCE/ DEST

Run some tests in scratch directories before applying it to large and important directories, because (IMO) rsync is idiosyncratic regarding whether directory names end with or without a /. Part of the Linux man page says:

A trailing slash on the source changes this behavior to avoid creating an additional directory level at the destination. You can think of a trailing / on a source as meaning "copy the contents of this directory" as opposed to "copy the directory by name", ...

like image 97
James Waldby - jwpat7 Avatar answered Sep 25 '22 19:09

James Waldby - jwpat7