LoginSignup
0
0

More than 5 years have passed since last update.

CUI でフォルダ内の全ファイルの合計サイズとファイル数を調べる方法 for macOS

Posted at

CUI でフォルダ内の全ファイルの合計サイズとファイル数を調べる方法

  1. ターミナルを開く
  2. 以下のコマンドを打ち込んで実行
function show_folder_size_and_file_count () {
    find "${1%/}" -type f -ls | awk 'BEGIN { sum=0;count=0 }; { sum+=$7;count++;printf "\rtotal %d Byte, %d files",sum,count }; END{ print "" }'
}
show_folder_size_and_file_count "<調べたいフォルダのパス>"

実行結果

MacBook-Air:tmp username$ function show_folder_size_and_file_count () {
>     find "${1%/}" -type f -ls | awk 'BEGIN { sum=0;count=0 }; { sum+=$7;count++;printf "\rtotal %d Byte, %d files",sum,count }; END{ print "" }'
> }
MacBook-Air:tmp username$ show_folder_size_and_file_count "${HOME}/Desktop"
total 2116481611 Byte, 9124 files

2.1 GB の場合、5 秒程度で処理は完了した。
また、awk コマンド内でコンソール出力を上書きしているため、ファイルサイズとファイル数のカウントがリアルタイムで更新される。

0
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
0
0