Operating System - HP-UX
1831349 Members
3074 Online
110024 Solutions
New Discussion

Re: determining directory size

 
SOLVED
Go to solution
denise_7
Frequent Advisor

determining directory size

I am trying to find the size of a directory that has other directories under it...such as sub-directories. I know du can help in this regard, but it gives size in block sizes. Anyway I can ge tit to report the size in megabytes? I am doing this because I am going to create another directory of similiar structure, but don't want to waste any resource by estimating the size. Oh, yea, I don't want to add up the files themselves. Also, when you run du, the results come back as block sizes only, how can you tell what size the block is in megabytes? Thanks in advance for any help.
5 REPLIES 5
Paul Sperry
Honored Contributor
Solution

Re: determining directory size

du -sk

-s Print only the grand total of disk usage for each
of the specified name operands.


-k Gives the block count in 1024-byte blocks.
Mladen Despic
Honored Contributor

Re: determining directory size

To get the size in kilobytes, use '-k':

du -ks /dir_name

If there are mount points under this directory, and you don't want to include anything under those mount points, then use '-x':

du -ksx /dir_name

So, if you set:

sizekb=`du -ksx /dir_name | awk '{print $1}'`

then

let sizemb=sizekb/1024 ; echo $sizemb

will give you the size in Mb.
James R. Ferguson
Acclaimed Contributor

Re: determining directory size

HI:

Do you mean filesystem size, as in a 'mountpoint' when you say "[I want...to create another directory of similiar structure, but don't want to waste any resource"?

Remember, once space (blocks) are allocated for a directory, that is, as files are added to it, the directory's space will never shrink. Therefore, a once-heavily populated, but now empty, directory will consume more space than a freshly made one.

Regards!

...JRF...
Helen French
Honored Contributor

Re: determining directory size

# du -k

This will report the size in Kbytes. You can then convert it to MBytes by deviding it with 1024.
Life is a promise, fulfill it!
T. M. Louah
Esteemed Contributor

Re: determining directory size

Find larger directories in /var:

du -kx /var | sort -rn > /tmp/du.var

Now look at the top lines in /var, u will see larger ones first, example :

/var/mail -- (someone got a giant email)
/var/spool -- (someone is printing a massive file)
/var/adm -- (probably a big logfile)
/var/adm/syslog -- (definitely a big logfile)
/var/adm/sw -- (patches, but cleanup will require space in /var)
/var/tmp -- (someone has a bunch of big files in /var/tmp)

Just to add to above !
Little learning is dangerous!