I want to copy files listed in a text file with absolute paths to another folder preserving the folder tree in the destination.



I want the source folder tree preserved within the output folder.

rsync -vR --include-from=in2.txt / $outd

results in the following and copies nothing:

$   rsync -vR --include-from=in2.txt / $outd
skipping directory /.
sent 17 bytes  received 12 bytes  19.33 bytes/sec
total size is 0  speedup is 0.00

trying cp with --parents:

while read p; do
  cp --parents "$p" $outd  # i had problem with unc path  //corp-fs01
done <in2.txt


cp: failed to get attributes of '/PMDA-SO5632': No such file or directory

How can I achieve the copy? It doesn't have to be rsync or cp.

  • what are you coping and why?
    – lnee
    Apr 1, 2022 at 19:16
  • 1
    you need to leave $p unquoted or the wildcards wont expand (read -r kind of mandatory).
    – user986805
    Apr 1, 2022 at 19:30

1 Answer 1


Don't think the -R attribute does what you intend to do. Usually, the archive attribute is enough. Rsync acts on the first rule that matches. And those objects not matching any rule will not be skipped and should be exclusively excluded.

rsync -va --include-from=in2.txt --exclude='*' / $outd

Parent directories have to be included too, or they will be excluded by '*', and rsync won't recursively traverse the directory structure.


Another solution would be to expand all file objects inside in2.txt before processed by rsync and use --files-from= instead. It will only copy objects included in the file without having to add any additional parent directories.

rsync < in2.txt -va --files-from=- / $outd

You must log in to answer this question.

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