Friday, June 29, 2007

Sort Files by Their Filesizes

Here's a convenient way of finding those space hogs in your home directory (can be any directory). For me, those large files are usually a result of mkfile event (testing purposes) and can be promptly deleted. Here's an example of its use.

# cd /export/home/esofthub
# ls -l | sort +4n | awk '{print $5 "\t" $9}'

Find recursively (a little awkward)
# ls -lR | sort +4n | awk '{print $5 "\t" $9}' | more


Anonymous said...

Nice, but why not use "du -sk *|sort -n" insted of big "ls -l | sort +4n | awk '{print $5 "\t" $9}'" ? :)

esofthub said...

appreciate the tip

Anonymous said...

You could also use in a built-in of ls:
ls -lhS

the -S option sorts by size.