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 .

2 Answers 2


I'd write it like this:

rsync -a root@somewhere:/folder/remote/*.{txt,jpg} .
  • 9
    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 Dec 10, 2010 at 15:04
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, 2017 at 20:26
  • I'm trying to get this to work. Shouldn't the second single quotation mark be after the brace expression, like this?: --include='*.{txt,jpg}'
    – mmortal03
    Sep 26, 2021 at 13:21
  • @mmortal03 No: the braces need to be expanded by the shell (they would have no meaning to rsync), whereas the asterisk needs to be passed to rsync (the shell wouldn't do anything useful with it). Sep 26, 2021 at 19:37
  • @Gilles'SO-stopbeingevil', what you said works. Your explanation makes sense. It didn't occur to me that quotes would be, effectively, breaking the brace expansion syntax. Maybe it can be thought of as if the expansion is interpreted as if the quotes aren't there?
    – mmortal03
    Sep 26, 2021 at 21:20
  • From elsewhere, courtesy of @Celada: "Brace expansion will never work inside quotes. Quoting removes the special meaning of { and } and many other characters. That's the whole point of quoting. If you want the characters to have their special meanings, don't quote them." unix.stackexchange.com/questions/205903/…
    – mmortal03
    Sep 26, 2021 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .