0

I have a list of directories within a file and I am attempting to copy those directories to a specified destination.

test.lst:

dir1
dir2
dir three

The list is within the same relative path as the directories as well as the destination, as such:

/dirs/dir1
/dirs/dir2
/dirs/dir three
/dirs/test.lst

Command executed in ./dirs:

cat test.lst | xargs -I {} cp -R {} ./_DEST

Expected result:

Directories in list copied from /dirs to /dirs/_DEST

Actual Result:

[.../dirs] # cat test.lst | xargs -I {} cp -R {} ./_DEST
cp: cannot stat `dir1\r': No such file or directory
cp: cannot stat `dir2\r': No such file or directory
cp: cannot stat `dir three\r': No such file or directory

I have tried adding the full path into the list for each directory (i.e '/...dirs/dir1'), but no help.
all dirs have been relaxed to 777 and are owned by same user/group that is executing the command.

2
  • Try the command dos2unix test.lst to remove the \rs.
    – FedKad
    Dec 21, 2020 at 15:29
  • Thanks, I believe that would have done it too, but I already stripped with sed.
    – ctroyp
    Dec 21, 2020 at 15:55

1 Answer 1

1

Your immediate issue is that your test.lst file appears to have DOS-style CRLF line endings (CR is denoted by the \r escape char).

You could convert the file with dos2unix, however instead of using cat and xargs -I {} I'd suggest removing the CR with sed then setting the xargs delimiter to newline ex.

sed 's/\r$//' test.lst | xargs -d '\n' cp -Rt ./_DEST --
2
  • You are correct. Thank you!
    – ctroyp
    Dec 21, 2020 at 15:54
  • @ctroyp The best way to say thanks and indicate correctness is to accept the answer and/or vote on it.
    – Quasímodo
    Dec 21, 2020 at 19:25

You must log in to answer this question.

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