[Shell command] find で空ファイルを検索する

作成日: 2026年09月21日

find コマンドの -empty を使用すると、サイズが 0 の空ファイルを検索できます。

例えば、下記のように検索対象のファイルを用意します。

mkdir -p sample
: > sample/empty.txt
printf 'hello\n' > sample/not-empty.txt

sample ディレクトリ以下の空ファイルだけを検索するには、下記のように実行します。

find sample -type f -empty

実行結果は下記のとおりです。

sample/empty.txt

-type f は検索対象を通常ファイルに限定し、-empty は内容が空のファイルだけに絞り込みます。

Shell command