Operating System - HP-UX
1758908 Members
2665 Online
108876 Solutions
New Discussion юеВ

ls -laR; du; | sort per directory to show decending order of file sizes from current directory

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Where do I start to do something like this;

Rewards for all suggestions!

Later,
Bill

It works for me (tm)
8 REPLIES 8
Andreas Voss
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Hi,

for du try:

du -a | sort -n

for ls try:

ls -laR | sort -k5n

Regards
Santosh Nair_1
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Not really sure if this is what you're looking for but how about:

find . -type -d -exec du -sk {} \; |sort -n

-Santosh
Life is what's happening while you're busy making other plans
Stefan Farrelly
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory


Hows this;

cd
du -k . | sort -nr | more
Im from Palmerston North, New Zealand, but somehow ended up in London...
Robin Wakefield
Honored Contributor
Solution

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Hi Bill,

This will format it on a per directory basis:

=============================================

find . -type f | xargs ll | awk '{print $5,$NF}' | while read line ; do
echo $(dirname "$line") $(basename "$line")
done | sort -k 2,2 -k 1n,1 |
awk '{if ($2 != dir) {print"====================";print "Directory - "$2;dir=$2}}{$2="";print}'

=============================================

Rgds, Robin.
Bill McNAMARA_1
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Sheesh, you're good at the awk stuff Robin!

Nice output...
seems to take a bit of time though, I'd really have prefered an identical or equivalent output a little easier..

Thanks,
Bill
It works for me (tm)
Santosh Nair_1
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

How about modifying the find in my previous posting to:

find . -type f -exec du -sk {} \; |sort -n

Its not sorted in directory order, but it does list all the files and their sizes.

Robin's scripting abilities are amazing...I'm suprised he's not royalty yet.

-Santosh
Life is what's happening while you're busy making other plans
Stefan Schulz
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Hi Bill,

hope i understood you right. You want a per directory list of files sorted by size, correct?

I would do something like:

for dir in `ls -d *` do
du -sk $dir/* | sort -rn
done

This will sort the files in each directory descending on filesize.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Robin Wakefield
Honored Contributor

Re: ls -laR; du; | sort per directory to show decending order of file sizes from current directory

Hi,

Actually, looking at Stefan's solution, mine's a bit OTT, but I've been waiting so long for these pages today, I got a bit carried away.

Rgds, Robin.