Sha*_*yay 72 ksh find disk-usage aix files
如何使用 du 命令获取所有文件及其子目录中所有文件的大小。
我正在尝试使用以下命令来获取所有文件(以及子目录中的文件)的大小
find . -type f | du -a
但这也会打印出文件夹大小。如何获取子目录中所有文件和文件的大小列表?我也尝试过,exec flag但我不确定在执行findinto的结果后如何将输出通过管道传输到另一个命令中du。
操作系统是带有 ksh shell 的 AIX 6.1。
rah*_*hmu 82
我通常使用该-exec实用程序。像这样:
find . -type f -exec du -a {} +
Run Code Online (Sandbox Code Playgroud)
我用 GNU find 在 bash 和 ksh 上都试过了。我从未尝试过 AIX,但我确信您的 find 版本有一些-exec语法。
以下代码段对列表进行排序,最大的在前:
find . -type f -exec du -a {} + | sort -n -r | less
Run Code Online (Sandbox Code Playgroud)
jw0*_*013 17
如果您有 GNU 实用程序,请尝试
find . -type f -print0 | du --files0-from=-
Run Code Online (Sandbox Code Playgroud)
Arc*_*ege 10
我一般使用:
find . -type f -print0 | xargs -r0 du -a
Run Code Online (Sandbox Code Playgroud)
Xargs 通常调用命令,即使没有传递参数;xargs du </dev/null还是会叫,xargs -r du </dev/null不会叫du。该-0参数查找以空字符结尾的字符串,而不是以换行符结尾的字符串。
然后我通常| awk '{sum+=$1} END {print sum}'在最后添加以获得总数。
小智 6
这是一个具有长参数名称和人工排序的版本。
find . -type f -exec du --human {} + | sort --human --reverse | head
Run Code Online (Sandbox Code Playgroud)
我还认为没有必要-a/--all传递给du.