Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a website for a client, and I just see a folder containing more than 1 million cache files.

I need to delete him, but i can't, i have this message : Argument list too long

I started to delete all files starting with aaa*, bbb*, ccc* .... but I do not want to spend my life... (rm -f aaa*.string.php)

How can i do that ?? Thanks !

share|improve this question

migrated from Feb 12 '13 at 13:31

This question came from our site for professional and enthusiast programmers.

try find /directory/path -type f -delete – Eddy_Em Feb 12 '13 at 10:23
up vote 6 down vote accepted

find and xargs are your friends, as always:

find -type f -print0 | xargs -0 rm

Or, for the special case of deletion (thanks, Eddy_Em):

find -type f -delete
share|improve this answer
The first command is hardly any better than rm *. – Lev Levitsky Feb 12 '13 at 10:25
@LevLevitsky: Yes, it is, because xargs is aware of command line length limitations and calls rm more than once. – thiton Feb 12 '13 at 10:25
Seems like I underestimated xargs, thanks for the info and +1 :) – Lev Levitsky Feb 12 '13 at 10:29
How can i know if this command is working well ? I don't want to wait 4 hours for nothing^^ – Clément Andraud Feb 12 '13 at 10:40
BTW there is another (not right, but available) way: unlink directory (without unlinking files) and run fsck. I didn't try its running time, but some people said, that it's even could be much less than find … -delete on some filesystems. – Eddy_Em Feb 12 '13 at 10:53

Instead of removing the individual files, you could remove and then re-create the folder itself:

cd folder/..
rm -rf folder
mkdir folder

If this works in your scenario, this will probably be much faster than any method based on explicitly enumerating and removing the individual files.

share|improve this answer
Hum ok, Your solution killed my server ^^ – Clément Andraud Feb 12 '13 at 10:27
I'll wait a bit for the command to stop – Clément Andraud Feb 12 '13 at 10:27


ls | xargs -n 200 rm -f

Will eventually remove everything

You can use grep to do pattern matching if you want to delete a subset of the files

share|improve this answer
Be careful when piping into xargs, it will happily interpret spaces as delimiters. Have a space in your filename, and have neverending fun. Standard pattern is find -print0 and xargs -0. – thiton Feb 12 '13 at 10:26

You must log in to answer this question.