How to resolve the ‘/bin/rm: Argument list too long’ error

While you are deleting some files which fill up your disk you may hit -bash: /bin/rm: Argument list too long error message.

So you can use below syntax to can delete those files:
# find . -name "DIR_PATH/*" -type f -exec rm -f {} \;
# find DIR_PATH -name "*" -type f -exec rm -f {} \;

You can also delete files with a specific extension (ex.: .php):
# find DIR_PATH -name "*.php" -type f -exec rm -f {} \;
# find . -name "DIR_PATH/*.php" -type f -exec rm -f {} \;

PS: In our case DIR_PATH=/var/spool/postfix/maildrop (there are like a half million files in that directory).

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.