我想创建一个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
解决方法:
使用GNU find和GNU排序:
find /some/dir -type d -exec du -hS {} + | sort -rh
du -S打印除子目录之外的目录大小.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。