I am trying to interactively remove files listed with their paths in a text file.

The command I am trying is:

xargs rm -i <filelist.txt

The error I get is:

rm cannot remove 'directory1/directory2/filename.extension\r': No such file or directory.  

I suspect the \r that has been added to the end of the filename is an indication of what is wrong, but I have no idea what it might mean.

I also tried:

xargs -rd '\n' --arg-file=filelist.txt rm -i --

with the exact same result.

Files are listed in filelist.txt in the format: directory1/directory2/filename.extension where directory1 is in the current directory.

  • first cd .. then run your command. You are effectively telling the machine to look for directory1 under directory1. That is where the confusion is coming from if you expressed your situation correctly.
    – MelBurslan
    Mar 31, 2016 at 13:23
  • Thanks for the suggestion, but going up one level means Linux cannot find directory1. (I also had to change the path to filelist.txt, but that sill dd not work. Interestingly, both commands result in the same error messages, with either directory as the current one.
    – Mike
    Mar 31, 2016 at 14:01

1 Answer 1


Your file list uses CRLF line endings, instead of standard LF, hence the \r in the error message. Try:

xargs -rd '\n' --arg-file=<(<filelist.txt tr -d '\r') rm -i --

(Assuming your shell has process substitution, i.e. ksh, bash or zsh.)

  • That almost worked. It got rid of the \r error, but did not pause for me to respond to the interactive input. I am somewhat confused as to how your command works, so I apologize for being so "needy". Thanks for getting me close!
    – Mike
    Mar 31, 2016 at 14:18
  • cat outputs the file contents, tr -d deletes the requested char (\r, i.e. CR) from the stream.
    – L. Levrel
    Mar 31, 2016 at 14:31
  • The second suggestion worked perfectly. I'm not sure how many you feel is too many. In my case it was under 100, and the command ran with no noticeable delay. Thanks very much.
    – Mike
    Mar 31, 2016 at 14:33
  • I added a link. The OS puts a limit on the number of arguments. On my current system it is a bit more than 2 millions.
    – L. Levrel
    Mar 31, 2016 at 14:39
  • @Mike See my edit for a more robust solution (assuming that your shell supports process substitution). Mar 31, 2016 at 23:35

You must log in to answer this question.

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