Results 1 to 10 of 10
I am trying to write a script that return the total used space for all sub directories 1 level down.
What I mean is imagine the following structure:
/home/bob contains ...
- 06-20-2007 #1Just Joined!
- Join Date
- Jun 2007
- Location
- Montreal
- Posts
- 2
Script returning total used space for every sub directory
I am trying to write a script that return the total used space for all sub directories 1 level down.
What I mean is imagine the following structure:
/home/bob contains d1 (3mb) , d2 (1mb) and d3 (5 mb)
home/bob/d1 contains d11 (1mb), d12 (10mb)
home/bob/d2 does not have any subdirs
home/bob/d3 contains d31 (35mb)
When I run my script against home/bob, it should return this:
d1 16mb
d2 1mb
d3 40mb
total 57mb
note 16mb for d1 is found by adding al the files in d1 (3mb) + all files in d11 (1mb) + all files in d12 (1omb)
when run in home/bob/d1 it should return
d11 1mb
d12 12mb
total 13mb
I tried a combo of for and du but I don't seem to be able to get to anything edible.
Any ideas ?
Thx in advance.
MB
- 06-20-2007 #2Code:
df -h --max-depth=1 /home/bob
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 06-20-2007 #3Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 06-21-2007 #4
ouch.......
you are right as usual.
thanx again smolloy.
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 06-21-2007 #5Just Joined!
- Join Date
- Jun 2007
- Location
- Montreal
- Posts
- 2
Thanks for your replies.
Indeed, du got the job done, df did not accept the --max-depth.
BM
- 06-21-2007 #6df is for calculating file-system disk space usage and du is for estimate file space usage.Indeed, du got the job done, df did not accept the --max-depth.
i confuses in df and du sometimes..
well ! i'll try to remember from now on..
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 06-24-2007 #7Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
Quite handy, thanks for the idea--it's in my /usr/local/bin. I think the
report is readable. You could use awk's "length" function to replace
the magic numbers.
#/bin/bash
#Dirs--says how big are files/directories
#
du --max-depth=1 | sed 's/\.\///g;$d' | sort -k 2 |
awk '{a+=$1; printf "%20s\t%8d\n",$2,$1} END {printf "%20s\t%8d\n", "TOTAL",a}'the sun is new every day (heraclitus)
- 06-24-2007 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 11-03-2007 #9Just Joined!
- Join Date
- May 2005
- Location
- India
- Posts
- 2
Hi I want to know is there any way with bash script to get from and to id with grep command in maillog of postfix
- 11-03-2007 #10
You don't want to put this request here, precisely. You want to click the "create new thread" link. And speaking of precisely, the more details you give us, the better we can help you.


Reply With Quote
