I want to do stuff like this:

echo myserver:~/dir/2/ | rsync -r HERE /local/path/

I want the output redirected to a specified location in the command. The echo stuff goes "HERE". What's the easiest way to do this?

  • Is there any purpose with your command that this rsync -r myserver:~/dir/2/ /local/path/ doesn't prove it? Oct 21, 2017 at 9:25
  • 1
    Yes, proof of concept. My real script is long and hard to read, so I made this one.
    – Lumify
    Oct 21, 2017 at 9:27
  • Didn't get you mean! You mean myserver:~/dir/2/ resulting from a script as its output and it's /to/ooo/ooo/oooo/looooong/path that you don't want to type in rsync?! Then PSkocik's answer is better choice` (surly I cannot change your choice) Oct 21, 2017 at 9:31
  • Yeah and I have variables that I can't even keep track of anymore.
    – Lumify
    Oct 21, 2017 at 9:37

3 Answers 3


You can use xargs or exactly this requirement. You can use the -I as place-holder for the input received from the pipeline, do

echo "myserver:${HOME}/dir/2/" | xargs -I {} rsync -r "{}" /local/path/

(or) use ~ without double-quotes under which it does not expand to the HOME directory path.

echo myserver:~/dir/2/ | xargs -I {} rsync -r "{}" /local/path/
  • xargs seems overkill for something where simple command substitution ($()) will do...
    – marcelm
    Oct 21, 2017 at 10:04
  • 2
    @marcelm : Thanks for the feedback. Yes I just wanted to show one of the many options possible to do. It is up to the OP to choose the best option. Am sure it didn’t deserve a -ve vote
    – Inian
    Oct 21, 2017 at 10:13


 rsync -r "$(echo myserver:~/dir/2/)" /local/path/

is the easiest way to do it.

Piping connects stdouts with stdins. Here you want the output to go to an argument, so you need something else than classical piping.

That something is command substitution ($()).


You may give rsync a list of files to download in a file or on standard input by using --files-from:

echo "dir/2/" | rsync --files-from=- -r user@server: /local/path/

The - makes rsync read from standard input. The server can't be given to rsync in this manner. There will only be a single connection made to the server and all files will be transferred over that connection.

If you use -a or --archive with --files-from then you need to explicitly add -r or --recursive if you want to recursion since that option, even though it's part of -a, is disabled when --files-from is used.

You must log in to answer this question.

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