If you try to use rm (Linux command) to delete too many files, it will often return the error “Argument list too long”.
To get around that problem, use this instead: find . -name "*" -print0 | xargs -0 rm
find . -name "*" -print0 | xargs -0 rm
The find command is quite flexible, and can be also used in combination to delete files in a certain date range, of a certain size, and even based on when a file was last modified. Such as this code, which deletes any file modified more than 2 days ago: find . -mtime +2 -print0 | xargs -0 rm
find . -mtime +2 -print0 | xargs -0 rm
I was trying to delete of a lot of files on my Linux server the other day. While trying to “rm *” I received this error message: /bin/rm: Argument list too long.
After a little research, I discovered that rm limits the number of files you can delete at any one time. You can overcome that problem by entering this command:
find . -name “*” -print | xargs rm
Note that this command deletes all files in the current directory. You will need to modify the command if you to limit your delete selection.