Thursday, December 7, 2006

/bin/rm: Argument list too long.


"what, a savvy guy like me having problems with a simple shell command like rm? Pleaaasee!!"


Linux always finds a way to make you humble again. Just when you begin to get cocky it has a way of slapping you behind the head and keeping you alert again. I just had such an experience...

while trying to delete a big directory (big as in many files....) i do this:

#rm -fr 200611*

and i get this:

/bin/rm: Argument list too long.

oh the agony... the intrigue... but don't worry... there is a way around this (as everything else in Linux).


strange as it seems most of the /bin/ commands have a limit of items it can process in order to avoid buffer overflows...so now it is time to ask our dear bash shell to help us out.

try this instead:

#find . -name '200611*'|xargs rm

this very simple script finds all files in the current directory which names starts with 200611 and then deletes them, passing the results via xargs and deleting them. xargs takes care for us to process batches of information big enough so the system may handle them without causing a buffer overflow. If more than one batch is needed, no problem xargs takes care of this.


Got slapped in the back also? kinda makes me feel in kindergarten all over again... don't eat the crayon...don't eat the crayon...



No comments: