Friday, March 30, 2007

How does one sort the files based on size in Unix ???

Again elementary but not used much

ls does not give an option to sort the files based on file sizes. (some os have -S option not sure which)

Here is a way to do it in a very generic way


bash-2.05# ls -hl /tmp/a.out /tmp/test.c |sort -k 4 -n
-rw-r--r-- 1 root other 0 Mar 30 21:41 /tmp/a.out
-rw-r--r-- 1 root other 108 Mar 29 11:49 /tmp/test.c

sort -k does the trick. So position can be any column in the output.
For more details man sort

1 comment:

Shantanu said...

Used it again to sort the wiki page based on the size listed in the second column