仅在“du”中打印终端目录?

仅在“du”中打印终端目录?

是否有通用的解决方案可以仅获取最深的目录?计算斜杠字符不起作用,因为如果我更改为--max-depth=4,最深的目录将不会都具有相同数量的斜杠。

标出的两个目录<<<<就是我想要的。

-bash-4.1$ du --max-depth=3 -h /Database/9.6/backups > x.x
du: cannot read directory `/Database/9.6/backups/lost+found': Permission denied
-bash-4.1$ cat x.x
16K     /Database/9.6/backups/lost+found
142G    /Database/9.6/backups/pgbackrest/archive/localhost  <<<<
142G    /Database/9.6/backups/pgbackrest/archive
4.9T    /Database/9.6/backups/pgbackrest/backup/localhost   <<<<
4.9T    /Database/9.6/backups/pgbackrest/backup
5.0T    /Database/9.6/backups/pgbackrest
5.0T    /Database/9.6/backups

答案1

您是否考虑过使用 来定位目录find
它同时具有-mindepth-maxdepth:)

$ du -h -cs $(find -maxdepth 4 -mindepth 4 -type d)
4.0K    ./ackups/pgbackrest/backup/localhost
4.0K    ./backups/pgbackrest/archive/localhost
8.0K    total

相关内容