Operating System - HP-UX
1834297 Members
1875 Online
110066 Solutions
New Discussion

Automatic Disk Usage report

 
SOLVED
Go to solution
Mark Treen_1
Advisor

Automatic Disk Usage report

Hi Guys and good afternoon.

I have a question which I think you guys can help me with.

Weekly I need to create a report which tells me for each directory below /home how much disk space it is occupying in kbs or meg prefer meg if poss)as a whole rather than per file within the home directory.

I know about du and dk but they dont give me the simple number I am looking for - for each directory below home, how much space in megs is it and its sub directores occupying.

As always thanks a million for the help

Mark
Mark Treen
10 REPLIES 10
Rodney Hills
Honored Contributor

Re: Automatic Disk Usage report

Did you know that du -k will display the space in 1k blocks?

Rod Hills
There be dragons...
Jeff_Traigle
Honored Contributor

Re: Automatic Disk Usage report

You must have missed the -s option for du to provide a sum instead a file-by-file report. The following should give you what you want in kilobytes:

du -sk /home/*
--
Jeff Traigle
Tiziano Contorno _
Valued Contributor
Solution

Re: Automatic Disk Usage report

Hi Mark:

for DIR in $(find /home -type d | awk -F'/' '{print $3}' | sort -u)
do
echo "$DIR is $(du -ks /home/$DIR | awk '{print $1}') Kb"
done

Regards.
Ninad_1
Honored Contributor

Re: Automatic Disk Usage report

Hi,

Or simply use

find /home -type d | xargs du -sk | awk '{print $NF,$1/1024,"MB"}'

Regards,
Ninad
James R. Ferguson
Acclaimed Contributor

Re: Automatic Disk Usage report

Hi Mark:

Rodney's suggestion deserved more merit. A simple:

# du -ks /home/*

...would have summarizied the 1K sizes of every directory in '/home' without spawning multiple processes through a series of pipes.

If you wanted to see the biggest-to-smallest users, just sort it thusly:

# du -ks /home/* | sort -k1nr

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor

Re: Automatic Disk Usage report

Hi Mark,
I use this script to get it.
HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Automatic Disk Usage report

Hi Mark,
I use this script to get it.

This is another one.

HTH,
Art
Ninad_1
Honored Contributor

Re: Automatic Disk Usage report

James,

I Guess Mark said that he wants to know usage of all directories under home and its subdirectories. So just du -sk /home/* wont give the usage of the subdirectories.

Regards,
Ninad
James R. Ferguson
Acclaimed Contributor

Re: Automatic Disk Usage report

Hi (again) Mark & Ninad:

Ninad, if Mark wants a summary of each directory beneath '/home' including all subordinate directories, then my suggestion as posted simply becomes:

# du -k /home/*

...and for a list in descending space utilization:

# du -k /home/* | sort -k1nr

...dropping the '-s' switch that causes summarization.

You are correct that the author asked "...how much space...it is and its subdirectories...".

*However*, the top-rated solution actually gives summarized values! As for speed, the suggestion I make ran in about 0.1 wall seconds compared to about 4.5 seconds for the other.

With my regards!

...JRF...


Tiziano Contorno _
Valued Contributor

Re: Automatic Disk Usage report

[..]which tells me for each directory[...]
not files that's why I had to use "find -d"

[...]as a whole rather than per file within the home directory[...]
"-s" option

[...]for each directory below home, how much space in megs is it and its sub directores occupying[..]
Here I think the poster pointed out "subdirectories" to mean he wants the dir in a whole, with its subdir computed.

I made a for cicle to add the cosmetic "dir is n Kb" :)