Shell command/script to delete files whose names are in a text file

Romonov picture Romonov · Apr 14, 2012 · Viewed 35.6k times · Source

I have a list of files in a .txt file (say list.txt). I want to delete the files in that list. I haven't done scripting before. Could some give the shell script/command I can use. I have bash shell.

Answer

yazu picture yazu · Apr 14, 2012
while read -r filename; do
  rm "$filename"
done <list.txt

is slow.

rm $(<list.txt)

will fail if there are too many arguments.

I think it should work:

xargs -a list.txt -d'\n' rm