アーカイブディレクトリとそのサブディレクトリはx日間変更されませんでした。

アーカイブディレクトリとそのサブディレクトリはx日間変更されませんでした。

私はしばらくの間ファイルサーバーをアーカイブする方法を探していましたが、まだうまく動作する解決策が見つかりませんでした。目標は、過去日に変更されていないファイルのディレクトリとサブディレクトリを検索することです。親ディレクトリまたはそのサブディレクトリにファイルが見つからない場合は、親ディレクトリ全体をアーカイブする必要があります(または少なくとも画面に印刷する必要があります)。どんな提案にも感謝します!こんにちはジョン

ベストアンサー1

簡単な答えは、他のファイルよりも最新のファイルを検索するfindコマンドの「newer」パラメータを使用することです。私たちが望むのは実際には反対なので、変更されたファイル(つまり更新されたファイル)を数えて何も見つからない場合は、ディレクトリ名を印刷するスクリプトが必要です。

DATE=`date -d "-30 days"` #Calculate a date 30 days before today
touch -d "$DATE" /tmp/newer #Create a temp file with the calculated date

#Assume we're passing in a list of directories
#We could just as easily find any directory below a certain point without
#newer files by setting DIR=`find /what/ever/directory -type d`

for DIR in $* 
do
    MOD=`find "$DIR" -newer /tmp/newer | wc -l` #Count the number of newer files
    if [ "$MOD" -eq 0 ] 
    then
        echo $DIR   # Nothing new in 30 days - Print the name of the Dir
    fi
done

おすすめ記事