Linux 查找大目录

du -h --max-depth=1

du -hm --max-depth=2 | sort -n

du -hm --max-depth=2 | sort -nr | head -12

以上都是当前目录,也可以指定目录

du / -h --max-depth=1

du / -hm --max-depth=2 | sort -n

du / -hm --max-depth=2 | sort -nr | head -12

看看具体比对效果

# du -h --max-depth=1
1.2G	./passageway
34G	./smart
779M	./lichuang
36G	.
# du -h --max-depth=2
16K	./passageway/web
1.2G	./passageway
45M	./smart/car
45M	./smart/common
55M	./smart/face
34G	./smart/admin
77M	./smart/customer
34G	./smart
20K	./lichuang/web
779M	./lichuang
36G	.

max-depth 是深度,几层的意思。

# du -h --max-depth=1 | sort -nr | head -6
779M	./lichuang
36G	.
34G	./smart
1.2G	./passageway
# du -hm --max-depth=1 | sort -nr | head -6
36171	.
34216	./smart
1177	./passageway
779	./lichuang

m 表示多少兆,加了之后,统一按照多少兆来排序。

# du -hm --max-depth=1 | sort -nr | head -6
36171	.
34216	./smart
1177	./passageway
779	./lichuang
# du -hm --max-depth=1 | sort -n | head -6
779	./lichuang
1177	./passageway
34216	./smart
36171	.

n 是升序, nr是降序。

# du -hm --max-depth=2 | sort -nr | head -10
36171	.
34216	./smart
33996	./smart/admin
1177	./passageway
779	./lichuang
77	./smart/customer
55	./smart/face
45	./smart/common
45	./smart/car
1	./passageway/web

# du -hm --max-depth=2 | sort -nr | head -6
36171	.
34216	./smart
33996	./smart/admin
1177	./passageway
779	./lichuang
77	./smart/customer

head 获取前几条。

posted @ 2021-05-13 09:37  TBHacker  阅读(119)  评论(0编辑  收藏  举报