Install the current version of Go in Ubuntu

After running:

$ sudo apt-get install golang

I ended up with an older version of Go than I needed:

$ go version
go version go1

Wanting to use scanner from bufio, I needed Go 1.1. Fortunately, you can get the latest version from https://launchpad.net/~duh/+archive/golang/+packages.

Simply run the following:

$ sudo add-apt-repository ppa:duh/golang
$ sudo apt-get update
$ sudo apt-get install golang

Now verify that you’ve got Go updated:

$ go version
go version go1.1.1 linux/amd64

Sort directory by file size with formatted size field using du -k | sort -nr | awk

du -k | sort -nr | awk '
BEGIN {
    split("KB,MB,GB,TB", Units, ",");
}
{
    u = 1;
    while ($1 >= 1024) {
        $1 = $1 / 1024;
        u += 1;
    }
    $1 = sprintf("%.1f %s", $1, Units[u]);
    print $0;
}
' > sort_file.txt