Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

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

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

add comment

10 Answers

up vote 2 down vote accepted

du -k | sort -n | tail

But this belongs on SU, not StackOverflow

share|improve this answer
add comment

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

du | sort -rn | head
share|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
add comment

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

du -ch /home |sort -nr|head
share|improve this answer
add comment

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"
share|improve this answer
add comment

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.

share|improve this answer
add comment

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
share|improve this answer
add comment

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
share|improve this answer
add comment

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

share|improve this answer
add comment

Try NCDU.

enter image description here

share|improve this answer
add comment

Use ls -S to sort by file size.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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