findを使ってファイルリストをフィルタリングする方法はありますか?

findを使ってファイルリストをフィルタリングする方法はありますか?

私の結果はlocate --existing --regex非常に迅速に得られた。同様のプロセスをfind実行するには数時間かかります。これは膨大な量です。

findこのファイルリストに追加のフィルタを適用したいです。

私が見つけた唯一の近道は、同じ検索を2回適用することです。まず:を使用して、これらのファイルを含むディレクトリのリストをインポートしてから、非再帰的locateに実行しますfind

# Abandoned Office temporary files
PATTERN='/foo/.+/~$[^/]+'

# locate doesn't re-enter the same path so sort before uniq is unnecessary.
# --existing is unnecessary, since locality of reference and thus
# performance and load are better when stat-ing the entries is done only
# once by `find`
locate --regex "$PATTERN" | xargs -d\\n -L1 dirname -- | uniq | \
  while read -r path; do
    find "$path" -maxdepth 0 -regex "$PATTERN" -type f -ctime +30 -exec rm '{}' ';'
  done

これを行うにはあまり複雑ではありませんか?

ベストアンサー1

おすすめ記事