Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It may sound strange, but I really want to copy only the existing files, so this files will be updated/overridden, and any new file will not be added.

I want to copy files of a single extension. It works well with this script line:

rsync -avm --include='*.bak' -f 'hide,! */' /Directory-to-be-backed-up/ /media/USB_stick

But I also want that the file to be copied only if it already exist in the destiny (overriding it).

For example, I have this 3 files in /tmp/a:


And this 2 files in /tmp/b:


I would like to update/override the existing files in /tmp/b using the ones in /tmp/a, but not copy any new file (like the /tmp/a/2.h).

Is there a way?

share|improve this question
up vote 3 down vote accepted

I'd reorder your command a bit, first I'd remove the --include and instead just put the *.bak right into the source path. Next you can add --existing to copy only existing files.

One possible way to do it (not tested):

rsync -avm --existing /Directory-to-be-backed-up/*.bak /media/USB_stick
share|improve this answer
I was going to suggest rsync ;) – bodhi.zazen Jan 11 '12 at 19:42

Your Answer


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.