I have a list of files that are in various directories on a remote machine that I want to rsync to a single directory on my local machine.

For an individual file user@remote:dir1/dir2/file1 ~/local does what I want; i.e. ~/local/file1

If I use --files-from then it creates the directory structure giving me ~local/dir1/dir2/file1 which I don't want.

n.b. I am aware that duplicate file names from different directories would cause files to be overwritten in ~/local

1 Answer 1


The documentation for rsync (man rsync) offers this particular scenario as one of its suggestions,

--files-from=FILE Using this option allows you to specify the exact list of files to transfer (as read from the specified FILE or '-' for standard input). It also tweaks the default behavior of rsync to make transferring just the specified files and directories easier:

o The --relative (-R) option is implied, which preserves the path information that is specified for each item in the file (use --no-relative or --no-R if you want to turn that off).


Applying this to your question,

rsync -av --files-from=/tmp/filelist --no-R user@remote:dir1/dir2/file1 ~/local

I would opine that having two or more files with the same name would have undefined behaviour, possibly causing rsync to fail with an error due to mismatching checksums. Don't do that.

  • Thanks, I'm aware there's an issue with repeated file names and I deal with it when creating my list.
    – Hipponax43
    Jul 2, 2021 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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