I want to sync some files from a remote server to my local computer. How can I make rsync to just copy the files with a certain file extension in the directory but no subdirectories?

I assumed this to be an easy task, but embarassingly I'm not getting it for nearly 2 hours. So could someone give me an example?

I did various experiments with something like the following command:

rsync -a --include=what? --exclude=what? -e ssh me@server.com:/test /test

migrated from serverfault.com Aug 23 '14 at 6:45

This question came from our site for system and network administrators.


If you just want one extension, in one directory, why not just use regular globbing?

rsync /home/you/rsync_this/*.jpg user@server:/remote/folder/

You can even copy multiple extensions with:

rsync /home/you/rsync_this/*.{jpg,png,gif} user@server:/remote/folder/
  • I was simply not aware of this... But it's acutally the easiest solution. – Michael Aug 21 '14 at 7:30

What about:

rsync $(pwd)/*.stuff  user@server:$(pwd)

$(pwd) will expand to the current dir on both sides and you will save yourself some typing ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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