説明する

説明する

私はこのスクリプトを持っており、それを単純化したいと思います。助けてくれてありがとう。

#!/bin/ash
chmod 775 /path/to/directory
chown -R http:http /path/to/directory
cd /path/to/directory
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

chmod 775 /path/to/directory1
chown -R http:http /path/to/directory1
cd /path/to/directory1
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

chmod 775 /path/to/directory2
chown -R http:http /path/to/directory2
cd /path/to/directory2
find . -type d -exec chmod 775 {} \; ; find . -type f -exec chmod 664 {} \;

ありがとうございます。

ベストアンサー1

#!/bin/ash
for i in \
         '/path/to/directory'  \
         '/path/to/directory1' \
         '/path/to/directory2' \
;do
    chmod 775 "$i"
    chown -R http:http "$i"
    cd "$i" && \
    find . \
       -type d -exec chmod 775 {} \; \
                  -o \
       -type f -exec chmod 664 {} \;
    done

説明する

dir1/2/3で同じ作業セットを実行するので、ループの下に移動するのは合理的です。

ブール論理ルールを使用すると、2 つの検索コマンドを 1 つの検索コマンドに移動することもできます。

おすすめ記事