私はしばらく探していましたが、簡潔な解決策が得られないようです。古いファイルを削除しようとしていますが、一部のサブディレクトリ (parm 経由で渡される) とその子サブディレクトリを除外しています。
私が抱えている問題は、subdirectory_name 自体が通知された期間 (parm 経由でも渡される) よりも古い場合、find コマンドが検索のリストに subdirectory_name を含めていることです。rm
実際には、コマンドのデフォルト オプションが であるため、remove でこれらのサブディレクトリを削除することはできませんf
。
スクリプトによって生成される find コマンドは次のとおりです。
find /directory/ \( -type f -name '*' -o -type d \
-name subdirectory1 -prune -o -type d -name directory3 \
-prune -o -type d -name subdirectory2 -prune -o \
-type d -name subdirectory3 -prune \) -mtime +60 \
-exec rm {} \; -print
これがファイルのリストです(およびfindコマンドによってもたらされるサブディレクトリ)
/directory/subdirectory1 ==> this is a subdreictory name and I'd like to not be included
/directory/subdirectory2 ==> this is a subdreictory name and I'd like to not be included
/directory/subdirectory3 ==> this is a subdreictory name and I'd like to not be included
/directory/subdirectory51/file51
/directory/file1 with spaces
これに加えて、スクリプトは次の 3 つのサブディレクトリの下にファイルを移動 (除外) しなくても正常に動作します:
subdirectory1
、subdirectory2
およびsubdirectory3
.
ありがとうございました。