0

I am trying remove files by names according this answer How to delete files listed in a text file

But get following error:

rm: cannot remove 'var/Resources/Images/fd29d33d.jpg'$'\r': No such file or directory

I understand that every line in txt file misses an / at the start and something wrong with end of lines: \r in the end (except last file). How can I change this command xargs rm < file to work properly with my file? File contains about 8kk lines

It is not a homework, I am not an admin and need this to be done.

Mateech
  • 131

1 Answers1

1

In order to add a / at the beginning of each file, and to remove the trailing characters after the first ', you can try this command instead of xargs rm < file:

sed 's/^/\//' file | sed "s/'.*$//" | xargs ls

If the above command correctly lists the files, you must change ls to rm so that the files are actually deleted, this way:

sed 's/^/\//' file | sed "s/'.*$//" | xargs rm

I hope this helps.