Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

up vote 7 down vote accepted

I'd write it like this:

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

 
discard

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.