-   Programming (
-   -   Help with file size script (

jpc82 03-30-2004 06:02 PM

Help with file size script
At my university we have a disk space quota, so I used to just run du -sh * to see what was taking up space, but the problem was that hidden folders would not show up. To solve this I created a simple script to do it for all folders. My problem is that my script will not work on folders with spaces in the name. Can any some look it over and suggest a solution?

for file in `ls -a`
if [ $file != "." -a $file != ".." ]; then
du -s $file
#du -s $file

Looking_Lost 03-30-2004 06:09 PM

quick way, at the start change IFS variable to a newline exclusively


jpc82 03-30-2004 06:11 PM

Wow, that was easy.


kooch 03-30-2004 07:33 PM

/* nevermind */

bigearsbilly 03-31-2004 04:47 AM

what about?


du -sh * .*

bigearsbilly 03-31-2004 04:48 AM

thats supposed to be

du -sh .* *

looks like DOS *.*

mgatny 03-31-2004 12:50 PM

Another way:

find -exec du -hs {} \;

Hko 03-31-2004 04:49 PM

That last one prints every single file. Bit of an overkill IMHO. For me the idea of "du" is to see a short list of the amount of data in the subdirs.

I use this in a script called "dusort" to produce a list of subdirs of the working dir sorted by size.

du -s * | sort -g | cut -f 2 | xargs du -hs

jpc82 03-31-2004 05:22 PM

the problem with du -sh .* * is that it will also evaluate ..

aluser 03-31-2004 06:41 PM

you can use '-type d' to find only directories:

find . -type d -exec du -sh {} \;

Hko 04-01-2004 05:55 AM

True, that's better.

All times are GMT -5. The time now is 03:01 AM.