开发者

How to chmod of subdirectories of a provided path (BASH)

I need a script that takes a single command line argument that is a directory path. The script should check the argument to determine if it is in fact a directory. If it is a directory, then the script should change the protection mode of any开发者_如何学运维 subdirectories located in it to 600. If the argument is not a directory, then an appropriate message should be printed out.

I have

if [ -d $1 ] ; then


else

echo "This is not a directory"

fi

Basically I don't know what to put on the blank line. I was fooling around with chmod but my line seemed to want to change the inputted path and not just the subdirectories.


if test -d "$1"; then
    find "$1" -type d -exec chmod 600 '{}' \;
else
    echo "Not a directory: $1" >&2
    exit 1
fi

Various variants may be faster, but depend on features not in ancient find or xargs.

find "$1" -type d -exec chmod 600 '{}' +
find "$1" -type d -print0 | xargs -0r chmod 600


([ -d "$1" ] && find $1 -type d -mindepth 1 | xargs chmod 600 | true) || echo 'Not a directory'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜