1

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

in2.txt:

//PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T070720.*
//PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T064927*
//PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T070210.xml

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

outd=/cygdrive/c/0/out27/
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

Yields..

//PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T070210.xml
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.

2
  • 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

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.

/PMDA-SO5632/
/PMDA-SO5632/data/
/PMDA-SO5632/data/vision_6830/
/PMDA-SO5632/data/vision_6830/image_data/
/PMDA-SO5632/data/vision_6830/image_data/top_surface/
/PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/
/PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/
/PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T070720.*
/PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T064927*
/PMDA-SO5632/data/vision_6830/image_data/top_surface/nok/220104/inner_rim_220110T070210.xml

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 .