Is there `find`’s `-exec` like option in `ack-grep`

ackfind

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?

Best Answer

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.