Friday, 23 November 2007

Finding the big files in unix

I'm blogging this because I never remember...

report on disk space usage (in unix)
df

figure out where all that usage goes
du -sk * | sort -n

4 comments:

  1. Doesn't the -h on du make the sizes in human readable formats? Seems that when I tried it, a folder with size 1.1 M showed up at the top of the list, when it should have shown up a the end of the list, as it was the biggest folder. It's better just to leave off -h. Makes reading the sizes a little harder, but the sorting is done correctly at least.

    ReplyDelete
  2. Thanks man. I didn't pay too close attention after I was like "hey, I can understand numbers like this better!".
    In the post I changed the "h" switch to a "k" for kilobytes. Not as nice as the human readable, but correct at least. ;-)

    ReplyDelete
  3. Actually, I was messing around with this on my laptop and found that -h is actually the default, so you have to use the m,k, or b option to get it to sort correctly. Personally, I just stick with b, so that I can see the actual size in bytes.

    ReplyDelete
  4. Sorry, forgot to add, the advantage of using -b, is that the command ends up as:
    du -bs | sort -n
    and it helps you find all the bs on your disk.

    ReplyDelete