Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 .
share|improve this question
up vote 12 down vote accepted

I'd write it like this:

rsync -a root@somewhere:/folder/remote/*.{txt,jpg} .
share|improve this answer
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
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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