#!/bin/sh MODE=${1:?the first argument of the command should be an octal-mode.} DIRECTORY=${2:?the second argument of the command should be a directory.} ( flock -n 9 || exit 1 find $DIRECTORY -exec ./chmod-one $MODE {} \; ) 9>./chmod-all.lock