Is there a generalized solution for getting only the deepest directories? Counting slash characters won't work, because if I change to --max-depth=4
, the deepest directories won't all have the same number of slashes.
The two directories indicated by <<<<
are the ones I want.
-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
lost+found
is locally deepest (it has no subdirectories) but you don't want it. So do you want "globally deepest"? In your examplelost+found
is not globally deepest because its depth is less than some other depth in the entire directory tree in question. This makes sense, but please confirm. If you want "globally deepest", is the depth of the deepest known in advance?--max-depth=3
.—max-depth
option in the question.