0

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

0

10 Answers 10

2

du -k | sort -n | tail

But this belongs on SU, not StackOverflow

0

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

du | sort -rn | head
1
  • 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, 2009 at 13:15
0

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

du -ch /home |sort -nr|head
0

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"
0

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.

0

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
0

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
0

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

0

Try NCDU.

enter image description here

0

Use ls -S to sort by file size.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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