rm Argument list too long

rm Argument list too long

rm * Argument list too long

The dreaded message when you are hurriedly trying to delete logs from your production machines because your /var partition is filling up fast and your machine is about to crap out.

Well, maybe that’s not the case for you, but if you are here, you are here because you tried to delete a bunch of files using a wildcard and well, rm refused to do it. There are a few workarounds floating around on the net about why this happens and why bash refuses to do it because yadda, but let’s be real. You are here because you need to delete a bunch of files. And chances are likely if you are on a prod server deleting logs, you are probably a bit apprehensive about rm’ing things anyway. One wrong slip and whoops there goes your root folder.

My recommendation on deleting a bunch of files?

Use the find command.

Why?

  1. You can see the list of files you are deleting before you pull the trigger.
  2. No more too many arguments.
  3. Because it’s super fun and easy.
  4.  It helps your ‘find’ foo, which, if you don’t have it already, it’s super handy.

This command will let you search, using wildcards, for the matching set of files you would like to delete. If you would like to search for directories, that’s fine too, just add -type d (dir) instead of f (file).

This will produce a list of files that match what you are searching for. Once you have your list set correctly, run the same command but put -delete at the end of it.

That’s all folks.