1

私はしばらく探していましたが、簡潔な解決策が得られないようです。古いファイルを削除しようとしていますが、一部のサブディレクトリ (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 つのサブディレクトリの下にファイルを移動 (除外) しなくても正常に動作します: subdirectory1subdirectory2およびsubdirectory3.

ありがとうございました。

4

2 に答える 2

2

次のコマンドは、1 日より古いファイルのみを削除します。以下の例に示すように、ディレクトリを除外できます。ディレクトリ test1 と test2 は除外されます。

find /path/ -mtime +60 -type d \( -path ./test1 -o -path ./test2 \) -prune -o -type f -print0 | xargs -0 rm -f 

-print を使用して削除される内容を確認することをお勧めしますが、

find /path/ -mtime +60 -type d \( -path ./test1 -o -path ./test2 \) -prune -o -type f -print
于 2013-06-14T20:55:32.910 に答える