aを満たすファイルの合計サイズを取得しようとしていますfind
。たとえば、次のようになります。
ls $(find -maxdepth 2 -type f)
ただし、この呼び出しはls
全体のサイズも生成しません。
ベストアンサー1
信じるかどうか、find
およびを使用してこれを達成することができますdu
。私は以前ブログに投稿した同様の技術を使用しました。その記事のタイトルは次のとおりです。[1行]:duを使用して、Linux上のファイルリストのディスク容量を計算します。。
投稿のポイントは次のコマンドです。
$ find -maxdepth 2 -type f | tr '\n' '\0' | du -ch --files0-from=-
はい
要約全体とともに、すべてのファイルのサイズが一覧表示されます。
$ find -maxdepth 2 -type f | tr '\n' '\0' | du -ch --files0-from=- | tail -10
0 ./92086/2.txt
0 ./92086/5.txt
0 ./92086/14.txt
0 ./92086/19.txt
0 ./92086/18.txt
0 ./92086/17.txt
4.0K ./load.bash
4.0K ./100855/plain.txt
4.0K ./100855/tst_ccmds.bash
21M total
メモ:私が知る限り、このソリューションにはGNUスイッチdu
のサポートが必要です。--files0-from=
du マニュアルページから抜粋
--files0-from=F
summarize disk usage of the NUL-terminated file names specified in
file F; If F is - then read names from standard input
また、このメソッドは、スペース、印刷できない文字など、ファイル名の特殊文字を処理できません。
はい
du: cannot access `./101415/fileD': No such file or directory
du: cannot access `E': No such file or directory
tr .. ..
これらの問題は、代替文字に置き換えるより多くのコマンドを導入することで解決できます。しかし、GNUのfind
。
改善する
あなたのバージョンがこのfind
スイッチ--print0
を提供している場合は、この注文を使用して印刷できないスペースや特殊文字を含むファイルを処理できます。
$ find -maxdepth 2 -type f -print0 | du -ch --files0-from=- | tail -10
0 ./92086/2.txt
0 ./92086/5.txt
0 ./92086/14.txt
0 ./92086/19.txt
0 ./92086/18.txt
0 ./92086/17.txt
4.0K ./load.bash
4.0K ./100855/plain.txt
4.0K ./100855/tst_ccmds.bash
21M total