Depending on your version of grep
, this might wait forever because you don't have given a file (or directory) name as argument; grep
's behavior to use the current working directory when -r
is specified is a rather new feature. Thus if your version is an older one, this your call might wait forever for input on stdin
. Just add .
as last argument to grep
to avoid this case.
To avoid issues with file names (which shouldn't be a problem in this case), it would be safest to call
grep -Zl -r 'Undelivered' . | xargs -0 rm --
This way, grep
outputs the matching file names zero-byte ('\0'
) separated, which avoids trouble with spaces and alike in file names. --
tells rm
to not treat the following arguments as options, i.e. if a file name starts with a -
it doesn't break.
To see whether this command does anything at all, you could add the -v
option to rm
, so you could see whether rm
does actually remove anything (in front of --
, of course).