bash Linux中如何显示每个子目录的磁盘使用情况?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43681022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show the disk usage of each subdirectory in Linux?
提问by Kurt Peek
I have a directory, /var/lib/docker
, which contains several subdirectories:
我有一个目录,/var/lib/docker
其中包含几个子目录:
/var/lib/docker$ sudo ls
aufs containers image network plugins swarm tmp trust volumes
I'd like to find out how big each directory is. However, using the du
command as follows,
我想知道每个目录有多大。但是,使用du
如下命令,
/var/lib/docker$ sudo du -csh .
15G .
15G total
I don't see the 'breakdown' for each directory. In the examples I've seen in http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/, however, it seems that I should see it. How might I obtain this overview to see which directory is taking up the most space?
我没有看到每个目录的“细分”。但是,在我在http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/ 中看到的示例中,我似乎应该看到它。我如何获得此概览以查看哪个目录占用的空间最多?
回答by AlecTMH
Use asterisk to get info for each directory, like this:
使用星号获取每个目录的信息,如下所示:
sudo du -hs *
It will output something like the below:
它将输出如下内容:
0 backup
0 bin
70M boot
0 cfg
8.0K data
0 dev
140K docs
回答by weirdan
Let shell expand the directory contents:
让 shell 展开目录内容:
du -h *
回答by ryekayo
In addition,
此外,
du -h <directory>
should do it.
du -h <directory>
应该这样做。
回答by schachan
Try using the max-depth
argument. It prints the total disk space usage for a directory (or file, with --all
) only if it is N
or fewer levels below the command line argument.
尝试使用该max-depth
参数。--all
仅当目录(或文件,带有)的总磁盘空间使用N
量低于命令行参数或低于命令行参数时,它才会打印总磁盘空间使用情况。
For e.g. the following command will show the disk space usage upto 3 level deep subdirectories
例如,以下命令将显示多达 3 级深子目录的磁盘空间使用情况
du --max-depth=3 -h
du --max-depth=3 -h
For informations on N-levels, use this du --max-depth=N -h
where N is a positive integer.
有关 N 级的信息,请使用它du --max-depth=N -h
,其中 N 是正整数。
回答by Skippy le Grand Gourou
ncdu
is also a nice way to analyze disk usage. It allows to quickly navigate through subdirectories and identify largest directories and files.
ncdu
也是分析磁盘使用情况的好方法。它允许快速浏览子目录并识别最大的目录和文件。
It should be available in most distributions official repositories.
它应该在大多数发行版官方存储库中可用。
回答by yoones
Call du
for each directory:
调用du
每个目录:
find . -type d | xargs du -csh
回答by Vipul Sharma
In addition you can simply use :
此外,您可以简单地使用:
du /directory
杜/目录
This would give of the space used by all of the sub directories inside the parent directory.
这将给出父目录中所有子目录使用的空间。