Linux du -h --max-depth=1 需要很长时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16030499/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:43:26  来源:igfitidea点击:

du -h --max-depth=1 takes long time

linuxdu

提问by ?zzesh

When I try to calculate the size of files and directory inside the directory it takes longer time. The command I used is du -ch --max-depth=1.

当我尝试计算目录中文件和目录的大小时,需要更长的时间。我使用的命令是du -ch --max-depth=1.

Is there any other way to calculate total size of files and folder?

有没有其他方法可以计算文件和文件夹的总大小?

Thanks

谢谢

回答by Jacob

The command duretrieves the disk usage of all files in the directory and all sub-directories (recursively) by default. So the time spent by durelates to the number of files analyzed. The options -sor --summarizeand --max-depthjust influence the output of the command (and not the scanning itself).

该命令du默认检索目录和所有子目录中所有文件的磁盘使用情况(递归)。所以花费的时间du与分析的文件数量有关。选项-sor--summarize--max-depth只影响命令的输出(而不是扫描本身)。

Some duoptions that limit the file scanning are --one-file-system, --exclude, and --exclude-from.

一些du限制文件扫描的选项是--one-file-system、--exclude 和--exclude-from。

If you don't want to recurse into the sub-dirs, you can use find instead, which gives you much more control about which files to analyze. But it can't sum up disk usage recursivly.

如果您不想递归到子目录中,您可以使用 find 代替,这使您可以更好地控制要分析的文件。但它不能递归地总结磁盘使用情况。

find /path/to/dir -maxdepth 1 -printf  "%k\t%p\n"

Notice, that %kalways return the disk usage in 1k blocks and the reported disk usage of sparse files might be less or slightly larger then the file size returned by %sof the lscommand. Thus '%k' behaves like the ducommand for single files.

请注意,这%k总是返回磁盘使用情况在1K块和稀疏文件所报告的磁盘使用量可能小于或稍大那么文件的大小通过返回%s的的ls命令。因此,'%k' 的行为类似于du单个文件的命令。

If you want to combine the features of findand duyou can combine both of them by something like.

如果你想的特点结合起来find,并du可以通过类似结合两者。

find . -maxdepth 1 -name "xyz*" -print0 | du --files0-from=-