Operating System - HP-UX
1834026 Members
2072 Online
110063 Solutions
New Discussion

Re: Finding out how much disk space is used in a certain directory

 
SOLVED
Go to solution
Ryan Gro
Advisor

Finding out how much disk space is used in a certain directory

Hey,

I'm trying to list how much disk space each directory (not mountpoint) uses.
I know about the du command, but is there a way to use that command without propagating all the way down all the directories?
I just want to list the disk usage of the directories in my current directory.

Thanks for your help,
Ryan
9 REPLIES 9
gabbar
Trusted Contributor
Solution

Re: Finding out how much disk space is used in a certain directory

this should do it.

du -sk /house/rahul/*

Ryan Gro
Advisor

Re: Finding out how much disk space is used in a certain directory

That's perfect thank you very much!
Kenan Erdey
Honored Contributor

Re: Finding out how much disk space is used in a certain directory

Hi,
rather than listing all directories recursively, to find out just top level directories' disk usage in your directory:

#cd /your_directory
#ll | grep ^d | awk '{system("du -sk "$9);}'

Kenan.
Computers have lots of memory but no imagination
Ryan Gro
Advisor

Re: Finding out how much disk space is used in a certain directory

Haha wow I don't understand any of that line but it works just great too. Thanks!
James R. Ferguson
Acclaimed Contributor

Re: Finding out how much disk space is used in a certain directory

Hi Ryan:

> # ll | grep ^d | awk '{system("du -sk "$9);}'

> I don't understand any of that line but it works just great too.

The ouput of an 'll' is filtered to take only directories --- lines that begin with the letter "d" in the 'll' mode column. The caret (^) anchors the match to the beginning of a line so the match is true or false based only on the first character there.

The 'awk' process then examines the ninth ($9) field of the 'll' output (which is the directory name) and uses that field as the argument to 'du'. To run the 'du', 'awk' spawns a new process using its 'system' function.

Regards!

...JRF...








Dennis Handly
Acclaimed Contributor

Re: Finding out how much disk space is used in a certain directory

#ll | grep ^d | awk '{system("du -sk "$9);}'
>I don't understand any of that line but it works just great too.

This just lists all of the files in your current directory, then selects lines starting with "d", for directories. Then invokes awk to do "du -sk" on each directory name, which is in field 9.

You can look at the stages in the pipeline:
ll | grep ^d | more
Ryan Gro
Advisor

Re: Finding out how much disk space is used in a certain directory

That makes lots of sense now thanks a lot. I still have a long ways to go understanding unix I guess. I've seen this "awk" command a few places before I just never knew what it did.
Dennis Handly
Acclaimed Contributor

Re: Finding out how much disk space is used in a certain directory

>I still have a long ways to go understanding unix I guess

Here is a thread that has links to documentation about sed, awk and perl.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=794554
James R. Ferguson
Acclaimed Contributor

Re: Finding out how much disk space is used in a certain directory

Hi (again) Ryan:

In addition to the books and references that Dennis pointed you toward, don't forget the excellent, free, manual collection:

http://www.gnu.org/manual/

The 'awk' guide is very good.

Regards!

...JRF...