1827667 Members
3845 Online
109966 Solutions
New Discussion

du command

 
SOLVED
Go to solution

du command

Greetings,

I'm trying to retreive files and there sizes using du -a -k which works to well. It goes down the whole folder tree to the smallest file. Is there away to have it stop at the last folder and report the size at that point?

Thanks,
Conrad
9 REPLIES 9
Pete Randall
Outstanding Contributor
Solution

Re: du command

Have you tried the -x option?


Pete

Pete
James George_1
Trusted Contributor

Re: du command

Hi

Try this

# du -sk * | sort -n Or

# du -sk * | sort -rn

Rgds / James

forum is for techies .....heaven is for those who are born again !!
Cem Tugrul
Esteemed Contributor

Re: du command

Conrad,
du -ks * |sort -n
would be solution for you...
Good Luck,
Our greatest duty in this life is to help others. And please, if you can't

Re: du command

Great,

Pete's -x option is the best so far. I now need to find a way to determine if the very first level returned is a directory then to return the files inside it. I may need to stick with the -a option and then take the file into ACCESS or something and force it to group the files that I need. More thought required.

Thanks.
Jeff Schussele
Honored Contributor

Re: du command

Hi Conrad,

This is what I use:

du -akx | sort -rn | more

This puts the grand total right up top.
Plus shows you the "hogs" up there as well.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!

Re: du command

Tkx Jeff,

I like this better. How would you sort the file so that it is done based on the path rather than the size?

Conrad
James R. Ferguson
Acclaimed Contributor

Re: du command

Hi Conrad:

To use Jeff's suggestion but sort the output using the filename (the second field), simply do:

# du -akx | sort -k2 | more

See the 'sort' manpages for more information.

Regards!

...JRF...

Jeff Schussele
Honored Contributor

Re: du command

Well...you'd have to sort differently- here's a sort EX:

du -akx | sort -rn | sort -k 2,2 | more

This will sort second field - i.e. path & THEN the size within.
Flip those around & you'll get size then path.




HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!

Re: du command

Thanks all, I went with Jeff's script and the rest will have to be done manually.