13

How to write those into one line, also without repeat the same path?

rsync -a root@somewhere:/folder/remote/*.txt .
rsync -a root@somewhere:/folder/remote/*.jpg .
17

I'd write it like this:

rsync -a root@somewhere:/folder/remote/*.{txt,jpg} .
  • 7
    This is a general technique that you can use with any command. The shell will repeat the argument, replacing the brace expression with each item in the list. It's called brace expantion – Shawn J. Goff Dec 10 '10 at 15:04
11
rsync -a --include='*.txt' --include='*.jpg' --exclude='*' root@somewhere:/folder/remote/ .

(Note that the final / in /folder/remote/, and the placement of --exclude='*' after the include rules, are important.) In shells that support brace expansion (e.g. bash, ksh, zsh):

rsync -a --include='*.'{txt,jpg} --exclude='*' root@somewhere:/folder/remote/ .

Add --include='*/' --prune-empty-dirs if you want to copy files in subdirectories as well.

  • rsync 3* seems to fail on * wildcards, the include|exclude work well though. – briankip Jun 21 '17 at 20:26

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.