#format text_markdown ワンライナー集 ============== Windows 10 でディレクトリ容量を計算する --------------------------------------- ###ワンライナー PowerShell を使う。 ```console $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?](https://superuser.com/questions/837016/how-can-i-check-the-size-of-a-folder-from-the-windows-command-line) ###ループで回して監視する 見にくいので複数行で書いておく。(`;` で繋げればワンライナーになる) 監視のためにタイムスタンプを入れてある。CTRL+C で止めるまで 1 秒毎にタイムスタンプとディレクトリのサイズを出力し続ける。 ```bash for (;1;) { sleep 1 $totalsize=[long]0 gci -File -r -fo -ea Silent|%{$totalsize+=$_.Length} $(Get-Date -format G)+" "+$totalsize } ``` 最後の出力部分を tee に入れるなどするとログが取れる。例えばループ内の最後の行を次のように変更する。 ```bash $(Get-Date -format G)+" "+$totalsize | tee-object -file dirsize.txt -append ``` 実行結果 ``` 2021/04/11 22:14:44 1716722748 2021/04/11 22:14:45 1716722748 2021/04/11 22:14:46 1716722748 ```