Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

TAG: rm

WTF: /bin/rm: Argument list too long

Imagine you got a directory, with millions of files in it. If you ever had the error message “/bin/rm: Argument list too long”,
you’ll know what I mean.

Here’s a workaround with find.

For example you wanted to delete all pdf files in the directory, here is how to do with find:

find -mindepth 1 -maxdepth 1 -type f -name '*.pdf' -delete

Let’s split the command:

find --> sure, the name of the command
-mindepth 1 --> find will search at least 1 level in depth
-maxdepth 1 --> find will search maximum 1 level in depth
-type f --> search only for files(see man find for other types)
-name '*.pdf' --> search for files ending with .pdf(use -iname for case insensitive search --> damn slow)
-delete --> deletes all matching files

With find you have the full control, and no need to be afraid, that you accidentally delete more files.

Have Fun!

There are no more results.