SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


dudirectory
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dudirectory [2013/05/16 11:56] (current)
sjoerd created
Line 1: Line 1:
 += 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.
 +
 +<​code>​
 +for i in `ls -1`; do if [[ -d $i ]]; then sudo du -sm $i; fi; done
 +</​code>​
 +
 +* 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:
 +<​code>​
 +-bash: [: ls: binary operator expected
 +</​code>​
 +
 +It was solved when I changed {{{[ -d $i ]}}} to {{{[[ -d $i ]]}}} (double brackets). ​
 +
 +{{tag>​scripts}}
  
dudirectory.txt ยท Last modified: 2013/05/16 11:56 by sjoerd