Operating System - HP-UX
1833777 Members
2376 Online
110063 Solutions
New Discussion

File size percentage with respect to the directory.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

File size percentage with respect to the directory.

Like the bdf command, I would like to find out the percentage of the files in the directory with respect to the size of the directory which contains them.

For example I have a /u01/export directory which is about 4GB used (we will take it as 100% just to compare with each file) and it contains about 20 files in it. Now I want to know in terms of percentages which file is having the maximum used percentage.

Thanks,

Gulam.
Everyday Learning.
7 REPLIES 7
Jim Turner
HPE Pro

Re: File size percentage with respect to the directory.

Gulam,

This may not get you where you want to be, but perhaps you can use it as the heart of a script to produce the percentages you seek.

Let's say I want to see what is soaking up /var. Here's the command I'd use:

du -kx /var | sort rn | more

This will give me directory usage of /var (and below) in kbytes sorted largest to smallest.

Cheers,
Jim
James R. Ferguson
Acclaimed Contributor

Re: File size percentage with respect to the directory.

Hi Gulam:

How about this for a start (after which you could embellish with 'awk'):

# du -x /usr |sort -rk1n

...JRF...
Satish Y
Trusted Contributor

Re: File size percentage with respect to the directory.

du -skx /u01/export | sort -nrk1 | more

You will get output in Kbytes followed by file name.

Cheers...
Satish.
Difference between good and the best is only a little effort
Satish Y
Trusted Contributor

Re: File size percentage with respect to the directory.

sorry, ignore -s option....

du -kx /u01/export | sort -nrk1 | more

Cheers...
satish.
Difference between good and the best is only a little effort
A. Clay Stephenson
Acclaimed Contributor

Re: File size percentage with respect to the directory.

Hi Gulam,

I whipped this up in about 3 minutes and it should be very close. You simply do dirpct.sh file1 file2 and it displays the filenamem, size, and pct used with respect to the current directory.

Regards, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: File size percentage with respect to the directory.

Hi Gulam,

I whipped this up in about 3 minutes and it should be very close. You simply do dirpct.sh file1 file2 and it displays the filenamem, size, and pct used with respect to the current directory.


.. oops, here's the attachment.

Regards, Clay
If it ain't broke, I can fix that.
Jim Turner
HPE Pro

Re: File size percentage with respect to the directory.

Gulam,

The sort args in my previous reply should of course be prefixed with a "-" as in

du -kx /var | sort -rn | more

Sorry for any confusion (and thanks for the "pro" hat!).

[no points on this one, please]