문제

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'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top