gnu --target-dir, how to fake with rsync?

Matt McCutchen matt at
Mon Oct 5 12:29:40 MDT 2009

On Mon, 2009-10-05 at 12:47 -0400, Sanjeev Sharma wrote:
> Is this in rsync and I just can't find it, or if not, is there a way
> to fake this OR, third possibility, is anyone working to add it?
> For those who've never used this option - for the GNU cp & mv type
> commands they have the
> --target-dir="dir"
> option.  It lets you put the destination directory as the first
> argument to cp and mv instead of the last argument.
> They added the option to get cp & mv working well with xargs  for
> stuff like this:
> find ./ -type file -mindepth 3 -print0 | xargs -r0 cp
> --target-dir=/home/sam/stuff/otherstuff/morestuff --
> then xargs puts all of the files found by find after the --

The obvious approach is to use a wrapper script that moves its first
argument to the end, like this:

exec rsync "$@" "$dest"

But if you're dynamically generating a list of source files, it might be
appropriate to use --files-from rather than passing them as arguments.


More information about the rsync mailing list