我想创建一个bash脚本,该目录在目录foo
内查找超过500MB的目录。如何查找最大的目录
我有这个命令,它以升序大小顺序查找与foo的目录。
du /foo/* | sort -n
问题在于它包含父目录的大小。因此,例如输出将是:
...
442790 /foo/bar/baz/qux
442800 /foo/bar/baz
442880 /foo/bar
我希望输出只显示/foo/bar/baz/qux
。由于父目录包含/foo/bar/baz/qux
,因此它们拥有自己的文件大小,但实际上,如果排除/foo/bar/baz/qux
,它们就是小文件夹。
一些伪代码:
if the current directory is greater than 500mb then
check next directory is parent to current directory (i.e `/foo/bar/baz` is parent of `/foo/bar/baz/qux`) then
takeaway size of parent from current.
if resulting size is greater than 500mb then
return row
else
go to next row
else
go to next row
else
go to next row
我现在是从移动应用程序,但我确定有一个'发现'选项来做到这一点。搜索SO。 – rpax