Use rsync to copy all files except for certain filenames with a certain extension

28

5

I have two same-size flash cards, and I want to copy contents of one to the other based on the following rules:

  1. I want all directories and subdirectories in place
  2. I want to exclude files of type .FOO, .BAR, and .ZIM (all other files are copied)
  3. Bonus: It'd be cool if it outputs the filenames as they are copied considering it will be copying ~8 GB of information

Could this be done with "find" somehow?

macek

Posted 2010-02-05T16:08:46.327

Reputation: 5 157

Answers

42

This would be significantly easier using rsync with its --exclude switch.

rsync -av --exclude='*.FOO' --exclude='*.BAR' --exclude='*.ZIM' /source /dest

The -v switch will provide verbose output on which files are being synchronised.

John T

Posted 2010-02-05T16:08:46.327

Reputation: 149 037

Little follow-up here: the copy finished and /src/* is now in /dest/src/* How to use rsync to get /src/* in /dest/*? – macek – 2010-02-05T17:32:48.573

Try /source/ /dest – John T – 2010-02-05T17:44:21.823

This doesn't work. I am still seeing *.FOO files being copied over. – Jake – 2017-08-26T00:03:18.553

It is specified how you should give the path for --exclude. If you have problems with it, check out this answer.

– totymedli – 2018-01-23T01:35:14.073

0

If you have large number of extensions to exclude you can make a file and write down all the extension or file to exclude and use only one exclude option to make it simple.

rsync -ravz --exclude='./abc,txt' /source /dest

It is always good to use z for compression and r option if you have to copy recursively.

amit singh

Posted 2010-02-05T16:08:46.327

Reputation: 157