Linux Argument List Too Long

0 comments

Encountered this cleaning out a directory overflowing with thousands of log files. When entering rm *.log or even a more narrow set such as rm *2011.log, the following error occurs.

sudo: unable to execute /bin/rm: Argument list too long

Solutions
Use find to output the file names one at a time, sending each to the rm (or some other) command.

find /home/username -type f -name "*.log" | xargs rm -f
find /home/username -maxdepth 1 -type f -name "*.log" | xargs rm -f
find $HOME -maxdepth 1 -type f -name "*.log" -exec rm "{}" \;