For some reason, since I set up my new machine, when I p4 sync I would get directories that aren’t writeable. This means that lzx files won’t compile since the swf needs to be written into the directory.

To work-around this, I tried to just set permissions on all the directories. My first attempt (below), didn’t work…. anyone know why? the second one is more verbose and did work.

$ find * -type d | chmod a+w
chmod: missing operand after `a+w’
Try `chmod –help’ for more information.

Verbose work-around:
$ for i in * ; do if [ -d $i ]; then chmod a+w $i ; fi ; done

A better answer: the chmod command does not accept arguments on stdin, so you can’t just pipe a file list to it:

$ find . -type d -print0 | xargs -0 chmod a+w

xargs is your friend

One thought on “bash: xargs is your friend

  1. Sarah, this post is from 2008 but as it’s beyond handy:

    $ find . -type d -exec chmod 775 {} ;

    So after you find whatever you want (all directories in this branch in this case) you then execute the chmod command with the curly brackets substituting in the found directories, and end the phrase with the sequence ;

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>