There are very long threads on this, I've read all that I could find, they don't answer my question.
The following is the best I can find to get a nicely formatted du
listing inside a folder:
du -hsc $(ls -A) | sort -h
However, it's not what I want exactly as I want it to filter out / not show files in the top folder. I just want to get a summary of the directories (including .*
directories) without the clutter of individual files. I think I would need to modify the ls
but don't know how?
Even better would be to do the above, and additionally show a line of just the combined size of all files that are in the top level of this folder to show alongside all of the subfolder totals if that's possible?
I don't see why you want to use
ls
here. A simplewould be sufficient. The terminating slash is important, as this instructs bash to only create directory names, and you need to set dotglob to include dot-directories (except
.
and..
). In my code I have also carefully saved the old dotglob setting and restored it otherwise. You only need to do this if your code is part of a large script where some part of it may rely on the default value for dotglob.Side note: A completely different approach would be to choose zsh instead of bash for your script. In zsh, you don't need to change any option, but just express in the pattern itself that you want to glob the dot-directories: