Ever wanted to do:
spud@spud-laptop:~$ dsize
4G .
3G Movies
115M .cache
3M .thumbnails
1M Code
560K .gnome2
46K .purple
I often need to know which folders are eating up all my HDD space. So I spent the day pestering the lovely people on irc.freenode.net, and ended up with this bash script:
Just save it as dsize, do chmod u+x dsize, and mv it into some folder bash will find (echo $PATH)
Well, I'm a noob in linux, I don't know a good place to stick this - please tell me!
If you wana get it recursing (see below), please go ahead!
Enjoy!
Ohmu
Code:#!/bin/bash # DirectorySize : Lists the size of folder and all subfolders, in decreasing order # Ohmu (sunfish7@gmail.com) 11 Nov 08 # Thankyou to # irc.freenode.net#linux # irc.freenode.net#awk # http://awk.freeshell.org/FormatFileSizes # # Example use: # # spud@spud-laptop:~$ ./dsize # 4 G . # 3 G .local # 115 M .cache # 3 M .thumbnails # 1 M .fr-6Q0eny # 560 K .gnome2 # 46 K .purple # # TODO: # Make it operate on a param (eg dsize /tmp) # Make it recursive. So that if any folder reports more # than (say) 1Meg, we go into that folder and rinse&repeat # eg # $./dsize -depth 0 (infinite) -granularity 1M # 4 G . # 3 G .local # 2.9G .local/fish # 3M .local/pudding # etc # anyone interested? :) I'm done for now! RSI'd out! # Ohmu # Get the byte usage for each subfolder, including . # Need some tricky syntax to get the .MyFolder folders # Try 'echo {a,b}c' then 'echo {,.}*' # [!.] takes out . and .. # We want . so we have to put it in manually # Sort, largest first # The awk script replaces eg 4784 with 4K # du -s {,.}[!.]* . \ | sort -rn \ | awk ' BEGIN { u[0]="K" u[1]="M" u[2]="G" } { # Get filesize and filename from paramlist # cannot use $1 and $2 as filename may contain spaces size=$1 # grab the number sub(/^[^\t]+\t+/, "") # Remove it from param list, and following spaces name=$0 # what is left is the name for (i=3; i>=0; --i) { if ( size > 1024 ^i) { # can sub %d with eg %.2f instead for 2dp precision printf "%d%s \t %s \n", (size / 1024^i), u[i], name next } } }' \ | more




Bookmarks