= Script: Bash: Du for every existing directory 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 = Error 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). {{tag>scripts}}