Shell parameter size limitation: Argument list too long
:: Tuesday, January 29th, 2008 @ 12:21:48 pm
:: Tags: Computers
I just came across the very-common Argument list too long parameter size issue when running some shell commands during the Wetpixel server migration (currently underway!).
chmod 777 * -bash: //bin/chmod: Argument list too long
I did a bunch of searches in teh Google, and because it took more than 5 minutes to find a good solution, I’m posting more information here.
My goal was to change the permissions of every jpg starting with “post.” At first, I did this (which was recommended by one site):
chmod 777 post*.jpg -bash: //bin/chmod: Argument list too long chmod 777 post-[1-5]*.jpg -bash: //bin/chmod: Argument list too long chmod 777 post-[1-3]*.jpg -bash: //bin/chmod: Argument list too long chmod 777 post-0*.jpg
(etc. etc. etc.)
But then, I found another hint (the comments are the useful part), and tried:
ls post*.jpg | xargs chmod 777
Much cleaner!
Command-line stuff is hard when you’re not in that environment a lot.
dude, eric, i could have told you that. next time, just ask me.
Kenny - with your journal output of 1-2 images per month, I’m sure you run into this problem once every, oh… 50-100 years or so.
But you’re right — I should have thought of you.
Fuck me. Kenny’s alive.
some tools (but not chmod) only take a single argument. for those you need “xargs -n 1 command” or use find:
find . -type f -name ‘post*.jpg’ -exec chmod 777 {} \; -print
find has the added benefit that it will traverse directory structures and apply the command to all matched files.
should both be single quotes around post*.jpg. for some reason the first got changed into a back-tick.
It’s Wordpress, trying to be “smart.” For that reason, I always wrap my code in PRE and CODE tags.