1

I have to delete files specified by remove.txt which looks like this:

    img_8138.dng.jpg
    img_8140.dng.jpg
    img_8141.dng.jpg
    img_8143.dng.jpg

I've tried several suggestions from the web:

while read file; do rm "$file"; done < remove.txt

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

rm $(cat /Volumes/space1/remove.txt)

xargs rm <remove.txt etc

The files are in the current directory some of which are to be deleted (remove.txt). Deletion works if I use rm on the current directory. But using the list I get the error below every time.

rm: cannot remove ‘img_8147.dng.jpg’: No such file or directory

Any ideas what's going wrong?

  • Do the lines in the file contain leading or trailing space characters? – nohillside Jun 20 '14 at 22:40
  • @patrix There is no leading or trailing space characters. – johne Jun 21 '14 at 14:06
  • 1
    Can you run your first command (while loop) with do echo rm "$file"; done and then just copy/paste one of the printed commands into the shell? – nohillside Jun 21 '14 at 14:45
1

That error is expected. There is no full path leading to the directory containing the files within remove.txt. Thus, when you run rm $(cat /Volumes/space1/remove.txt) outside of the directory these files reside in, you get that error.

Simply run:

cd /Volumes/space1; rm `cat remove.txt`

Or modify the remove.txt file to include the full path.

  • I neglected to mention in my post I had also tried with absolute paths. I checked patrix's suggestion about extra spaces, no luck. Then I tried your version and others I had used yesterday. All trys resulted in that darn error. – johne Jun 21 '14 at 14:14
  • "I neglected to mention in my post I had also tried with absolute paths." What method did you use when you attempted this? I suggest modifying the original question to include this information for clarification's sake. Cheers. – njboot Jun 22 '14 at 0:07

You must log in to answer this question.

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