Have you ever experienced that you remove command can’t remove anything, its just replies you with error. What happens when all of a sudden your command rm can not remove anymore? What else command you can use to remove? At some point in your Linux life you’ll come across a directory of session files (or something similar) that you want to remove. But, when you try to remove the files with linux’s rm command you’re met with the error message:
$ rm -rf *
$-bash /bin/rm: Argument list too long.
Well, you might try this command instead:
$ find . -type f -delete
(The find command is much quicker at listing files from a directory, and newer versions of “find” have -delete built in, which will allow you to remove files very quickly.)
Let’s say we’re looking to delete files named session_848938, session_45949343, session_454344, etc.. and they live in /path/to/files/
$ find /path/to/files/ -name “session_*” -delete
If you are absolutely sure that you want to remove everything in the directory use xargs. This is much more efficient.
$ find . -name ‘session_*’ | xargs rm