List all subfolders in current location and calculate their sizes



So, there is probably one milion ways of achiving same result, but this is how i do it.

The command (or rather script) looks like so:

$ for each in $(echo */ | sed "s/ /\n/g" | sed "s/\///g");  do du -hs "$each"; done;

If you want to save it as alias permanently:

$ echo $'alias ds=\'for each in $(echo */ | sed "s/ /\\n/g" | sed "s/\\///g");  do du -hs "$each"; done;\''>>~/.bashrc

and if you don't want to wait for next shell login for it just source the .bashrc file:

$ source ~/.bashrc

So now you are good to take it for a spin:

$ chm@chm.dev 12:10:09 /home →  cd /var/www/ && ds
52M alltube
47M grav
8.0K html
6.5M leed
584M mattermost
136K mumbleserver
2.5M rss-bridge
166M wallabag2
chm@qchm.dev 12:10:40 /var/www →

Keep in mind that in this simple version of it you cannot pass path. It will always list current path.
Of course it wouldn't take much of an effort to make it work like that, but for me way it works is fine.

Recent Posts

Quick formatted {dd-mm-yy hh:mm} date output in JavaScript

Dependency free module to copy all files (sync) from directory in nodejs

Git repository as dependency in package.json.

Iterating through nested JavaScript object and extracting data.

Modules Cheatsheet

Ultimate slugify function

XPath cheatsheet

Vanilla JS XPath query function

Online code utilities

← Back to all posts