Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
how do you sort du output by size?

I have a text file generated from the output of

du --max-depth 1 -h > sizeOfHomeFolder.txt

It's contents are in this format:

$ cat sizeOfHomeFolder.txt  | head
776K    ./Expensemanager
8.0K    ./workspace
4.0M    ./mysql-tutorial
3.6M    ./temp
26M ./Desktop
4.0K    ./Ubuntu One
4.0K    ./Photos
4.0K    ./Public

I need to sort this file based on 1st column i.e. the size.

How to do this with the help of sort or sed or any other common unix utility ?

share|improve this question

marked as duplicate by enzotib, jw013, Renan, jasonwryan, Gilles Sep 1 '12 at 23:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

sort du output by size duplicate? – jw013 Sep 1 '12 at 13:03
Thanks cat file | sort -h worked. As simple as that :) – mtk Sep 1 '12 at 13:06
up vote 5 down vote accepted

If you have a not too old version of GNU sort, you can do

sort -k 1,1h < input.txt

-h is for "human" sort and is required to know that 1.0M is indeed larger than 512K.

share|improve this answer
+1 for sort -h. it's very useful, esp. for things like sorting du -h. according to the changelog, -h was added to GNU sort on 2009-05-26 – cas Sep 1 '12 at 14:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.