是否有可能在Unix中使用ls列出子目录的总大小及其所有内容,而不是通常的4K(我假设)只是目录文件本身?
total 12K
drwxrwxr-x 6 *** *** 4.0K 2009-06-19 10:10 branches
drwxrwxr-x 13 *** *** 4.0K 2009-06-19 10:52 tags
drwxrwxr-x 16 *** *** 4.0K 2009-06-19 10:02 trunk
在翻遍了手册之后,我一无所获。
是否有可能在Unix中使用ls列出子目录的总大小及其所有内容,而不是通常的4K(我假设)只是目录文件本身?
total 12K
drwxrwxr-x 6 *** *** 4.0K 2009-06-19 10:10 branches
drwxrwxr-x 13 *** *** 4.0K 2009-06-19 10:52 tags
drwxrwxr-x 16 *** *** 4.0K 2009-06-19 10:02 trunk
在翻遍了手册之后,我一无所获。
当前回答
你 -短信 * |品种编号
按大小输出
其他回答
如果你想要更多地控制目录列表的大小,你可以使用阈值(-t)开关,如下所示:
$ du -ht 1000000000 | sort --reverse
磁盘使用率 人可读的格式 T -阈值大小
在这里,我们想要列出大小大于1GB的所有目录。
$ du -ht 1G | sort --reverse
解释:
wiki中描述的单位如下:
K, M, G, T, P, E, Z, Y(1024的幂)或 KB, MB, GB, TB, PB, EB, ZB, YB(1000的幂)。
要以ls -lh格式显示,请使用:
(du -sh ./*; ls -lh --color=no) | awk '{ if($1 == "total") {X = 1} else if (!X) {SIZES[$2] = $1} else { sub($5 "[ ]*", sprintf("%-7s ", SIZES["./" $9]), $0); print $0} }'
Awk代码解释:
if($1 == "total") { // Set X when start of ls is detected
X = 1
} else if (!X) { // Until X is set, collect the sizes from `du`
SIZES[$2] = $1
} else {
// Replace the size on current current line (with alignment)
sub($5 "[ ]*", sprintf("%-7s ", SIZES["./" $9]), $0);
print $0
}
样例输出:
drwxr-xr-x 2 root root 4.0K Feb 12 16:43 cgi-bin
drwxrws--- 6 root www 20M Feb 18 11:07 document_root
drwxr-xr-x 3 root root 1.3M Feb 18 00:18 icons
drwxrwsr-x 2 localusr www 8.0K Dec 27 01:23 passwd
Du -sch *在同一目录下。
du -sh * | sort -h
这将以人类可读的格式显示。
你 -短信 * |品种编号
按大小输出