I have a directory from which i want to delete some stuff.

So id like to see the heavier files.

du -ch will bring too many information, so i was thinking something like

du -ch | sort by size| head

The sort by size part is troubling me

Any thoughts?

Thanks in advance

link|improve this question
belongs on superuser.com – ax. Oct 22 '09 at 13:14
yes , voting to close. Sorry – Tom Oct 22 '09 at 13:16
feedback

migrated from stackoverflow.com Oct 22 '09 at 13:22

This question came from our site for professional and enthusiast programmers.

10 Answers

up vote 2 down vote accepted

du -k | sort -n | tail

But this belongs on SU, not StackOverflow

link|improve this answer
feedback

My first thought is that you can't use -h on a du that you're going to sort. Try:

du | sort -rn | head
link|improve this answer
Wouldn't -r sort it reverse order and then you need |head instead of |tail? At least, on Solaris sort -n sorts in accending order – DVK Oct 22 '09 at 13:15
feedback

if you want to see "heavier" files, for which i assume they are bigger size files..

du -ch /home |sort -nr|head
link|improve this answer
feedback

I have an (csh) alias "large" which shows the 10 largest files in my current directory:

alias large     "ls -l  \!* |sort -k5 -rn |head -10"
link|improve this answer
feedback

ls -S

to sort by file size.

link|improve this answer
feedback

Depending on the version of du, I like the following:

du -ckhs *

It pulls just the sizes of the items (kind of a top-level only type of thing) in the current directory (sizes of files and sizes of child directories (without listing everything in each)).

As chaos said, you can't sort to have things show up correctly with -h, but it at least gives a good quick overview of sizes without going into too much detail.

link|improve this answer
feedback

This rather lengthy function will display a sorted list with human-readable sizes:

dus () { du -bh ${1:+$1/}* |
    awk 'BEGIN {KMG="KMG"} 
        {printf "%s %08.2f %s\t%s\n",
        index(KMG,substr($1,length($1))),
        substr($1,0,length($1)-1),
        substr($1,length($1)),$0}' | 
    sort -r |
    cut -f 2-
}

which you can then pipe through head:

dus | head

It accepts a directory as an argument:

dus /usr/local
link|improve this answer
feedback

Typically I will use du -s * | sort -nr for this, and work my way down into the directories with larger sizes. The -s option makes it display the total for each item instead of recursing.

eg:

bcl@fozzy:~$ du -s * | sort -nr
171900  wiki
169932  bb.mail.tar.bz2
112772  tmp
44416   d.mail.tar.bz2
4148    src
2012    public_html
880 Mail
144 sha-search
72  logs
20  tt.txt
16  Maildir
16  brianlane_html
12  Temporary Items
12  Network Trash Folder
8   calendar_html
4   wiki_html
4   procmail.bcl
4   id_rsa.pub
4   foo.sh
4   fetchmail.bcl
4   bb.procmailrc
0   time.out
link|improve this answer
feedback

Personally I find kdirstat to be very useful to figure out where my disk space has gone. It sorts everything by size, and shows a somewhat useful visual 'treemap' that lets you roughly gauge by sight where space is being used.

enter image description here

link|improve this answer
feedback

Try NCDU.

enter image description here

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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