Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a MacbookPro Lion, and I have tried to archive my files that is tried to copy and overwrite if the source is newer than the destination. I tried the following command

cp -u source destination

but it says, -u is illegal. I also did not find --update or -u in the man cp.

Can you please help, what can I do in this situation?

[I have the question moved over here from SO, so feel free to answer it once more. I hope this is the right way of dealing with this]

share|improve this question
2  
Install GNU Coreutils. –  Keith Thompson Dec 5 '12 at 23:11
    
Any love for rsync? –  Mike Weller Dec 7 '12 at 13:26
add comment

3 Answers

up vote 2 down vote accepted

Probably the easiest solution would be to use rsync. It is a backup application that can do what cp -u does (and much, much more).

The basic usage would be something like :

rsync -u source destination

However, you really should check out the man page because there are MANY useful options.

share|improve this answer
add comment

You can use the -nt condition:

[[ source/$file -nt destination/$file ]] && cp source/$file destination/$file

Just run this for all files (via a loop or through find).

share|improve this answer
add comment

I have installed GNU Coreutils with MacPorts by

sudo ports install coreutils findutils 

findutils are not necessary but they suggested to install it too.

I followed the idea from Keith Thompson, (kudos!). It works greatly, the "advanced" copy command is now:

/opt/local/libexec/gnubin/cp

It does not have a man page, but has a long, man-style help with the --help option.

share|improve this answer
    
I reassociated this question with your account, so you should be able to comment, accept answers, etc. –  Anna Lear Dec 6 '12 at 3:41
    
Thank you, Anna! –  Barnabas Szabolcs Dec 6 '12 at 5:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.