ワンライナー集

Windows 10 でディレクトリ容量を計算する

ワンライナー

PowerShell を使う。

$totalsize=[long]0;gci -File -r -fo -ea Silent|%{$totalsize+=$_.Length};$totalsize

ソース: How can I check the size of a folder from the Windows command line?

ループで回して監視する

次のようなファイルを PowerShell スクリプト (.ps1) として保存して実行。
監視のためにタイムスタンプを入れてある。CTRL+C で止めるまで 1 秒毎にタイムスタンプとディレクトリのサイズを出力し続ける。

for (;1;) {
    sleep 1
    $totalsize=[long]0;
    gci -File -r -fo -ea Silent|%{$totalsize+=$_.Length};
    $(Get-Date -format G)+" "+$totalsize
}

これを tee に入れるなどするとログが取れる。

PS > .\dirsize.ps1 | tee-object -file output.txt

実行結果

2021/04/11 22:14:44 1716722748
2021/04/11 22:14:45 1716722748
2021/04/11 22:14:46 1716722748

misc/oneliners (最終更新日時 2021-04-11 22:19:45 更新者 dossist)