3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Linux】大量のファイルを、サーバ負荷をあまりかけずに削除する方法

Posted at

あるプロジェクトで特定のディレクトリ下に、キャッシュファイルが4000万件もできてしまった。

# ls -lrt cache/db  #db下に4000万件ファイルがある

愚直にrm

$ rm -rf cache/db/*

結果

削除されない。おそらくファイルインデックスを作成するだけでCPUパワー持って行かれている感じ。

find + rm

$ find cache/db/ | xargs rm -rf 

結果

削除されるが、サーバ負荷がすごい。コマンド流しっぱなしはできない。

find + head + rm

$ find cache/db/ -type f | head -1000000 | xargs rm -rf 

結果

findの出力を絞ることにより、サーバ負荷を上げすぎず削除が可能。
ただし、40回実行した。。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?