6

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.

Zombo
  • 1
  • 62
  • 391
  • 407
Fleea
  • 69
  • 1
  • 3

1 Answers1

15

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", ...

James Waldby - jwpat7
  • 8,593
  • 2
  • 22
  • 37