This is a short special page just dedicated to one command or script. The purpose here is just for me to learn scripting. I think most people will think these snippets are too simple too take notice from.
for i in `ls -1`; do if [[ -d $i ]]; then sudo du -sm $i; fi; done
ls -1 lists all files and directories each on a separate line
[ -d ] is true if listed variable is a directory
sudo provides the correct rights to read all files listed beneath the directories
I got this error while running the line:
-bash: [: ls: binary operator expected
It was solved when I changed [ -d $i ] to [[ -d $i ]] (double brackets).
Discussion