Delete files specified by the output of find: rm thinks argument list is too long.

findrm

When I run the following command, it gives me an error:

$ rm -f `find /home/domain/imap/domain.com/*/Maildir -mtime +190 | grep -E '/cur/|/new/'`
-bash: /bin/rm: Argument list too long

How can I run it without the error? (Or how can I put it in .sh?)

Best Answer

Well I would be tempted to do something like this instead, making the entire operation a single command.

find /home/domain/imap/domain.com/ -mtime +190 \
     \( -ipath '*/Maildir/new/*' -o -ipath '*/Maildir/cur/*' \) \
     -delete
Related Question