Use rsync to copy all files except for certain filenames with a certain extension
44,806
Solution 1
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.
Solution 2
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.
Related videos on Youtube
Author by
macek
Updated on September 17, 2022Comments
-
macek over 1 year
I have two same-size flash cards, and I want to copy contents of one to the other based on the following rules:
- I want all directories and subdirectories in place
- I want to exclude files of type .FOO, .BAR, and .ZIM (all other files are copied)
- 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 over 14 yearsLittle follow-up here: the copy finished and /src/* is now in /dest/src/* How to use rsync to get /src/* in /dest/*?
-
John T over 14 yearsTry
/source/ /dest
-
Jake over 6 yearsThis doesn't work. I am still seeing *.FOO files being copied over.
-
totymedli over 6 yearsIt is specified how you should give the path for
--exclude
. If you have problems with it, check out this answer. -
Chris L. Barnes over 3 yearsIt is not always good to use z for compression. Unless you are transferring over a network you know to be slow, compression will slow you down. Also, if you are transferring compressed files (e.g. jpeg, mp3, most video formats), or have a slow CPU, it'll just waste time.