I want to remove all texts that include string foo.
I can list all files by ack-grep foo, but I couldn't find a way to remove all files like -exec rm {} option like find.
How can I delete all files that contains particular string?
With GNU xargs:
ack -l --print0 foo | xargs -r0 rm --
ack's --print0 and xargs' -0 cause ack and xargs to write and read using NUL as the delimiter, which guarantees proper filename handling. Without it, xargs will accept a far more wide range of characters as a delimiter.
You can use option -l with grep and ack which lists only filename:
grep -l --null foo ./* | xargs -r0 rm
or:
ack -l --print0 foo ./* | xargs -r0 rm --