Howdy folks.
I have a problem - I'm sure the answer is very simple, but I can't work it out.
I want to create a UNIX shell script that does what I've been doing in DOS batch files for years - that is, backing up files. By which I mean copying files from a source directory to a target directory, only if a) the file doesn't exist at the target, or b) the file does exist but is older than the source.
In DOS, I did something like this:
xcopy c:\path\directory\*.* x:\backup\ /d /e
Where x was a networked drive, /d meaning only copy files newer than the target, /e meaning recurse into subdirectories.
In UNIX, I'm close but no cigar yet... I have the following:
cp -r /testdir/source/ /testdir/target/
This works in that it copies files, leaving the originals behind and recursing into subdirectories, but it doesn't only copy source files if they're newer than the target. It copies eveything.
I have read in a few different places that cp accepts the -u ('update' I think) option, to make it only copy newer files, but I can't get this to work. If I write cp -u, I am told that 'u' is an 'illegal option' for cp.
So, is there a way to get the behviour I'm after? Am I right to be using cp, or is there a better function to do what I want?
Doing all this on Mac OS 10.3.9, using the terminal, tcsh.
Very grateful for any help.
Cheers.