Argument List Too Long?
Posted in Tech
Forenoon watch, 1 bell (8:37 am)

I was working yesterday when I found that my /tmp directory was big—so big I couldn’t get a directory listing. rm and find all returned the error Argument list too long. My ARG_MAX environment variable (getconf ARG_MAX) is set to 131,072. That’s always been enough for me before.

By working around a bit, I found that the large bulk of the /tmp directory was full of YaST2 directories (SuSE’s setup and system management utility). So how do you remove so many directories? xargs to the rescue!

Although it took several hours to run, this command removed all my junk directories and brought /tmp back under my direct control. It also took around 1Gb of memory, but thankfully I never had to hit the swap:

find /tmp -maxdepth 1 -name 'YaST2-*' -type d -print | xargs --max-args=100 rm -rf

Make sure you quote the -name argument, otherwise the shell unglobs the filenames and tries to put them all on the command line, which still returns the Argument list too long error.

Leave a Comment »