disk snippets

How to list and sort directories by size in Linux/Unix

Tagged list, directories, size, du, sort, disk, harddisk, space  Languages bash

For human-readable output use the following command:

du -sh /* | sort -h

Use this command to find the directories taking up the most space:

du -k | sort -nr | more

The du command along with the -k switch lists all directories and their respective size in kilobytes. The sort command sorts the output so that the largest directory is shown first in the list. The -nr switch reverses the list and uses only numbers when sorting.

Here’s an example of the output:

12939451  .
1814892  ./abcdef
1219582  ./abcde
839586  ./abcd
718330  ./abc
695610  ./ab
690380  ./a

Resizing a Xen disk image partition

Tagged xen, disk, image, resize  Languages bash
# Stop & backup
xm shutdown sandbox
cp -a sandbox/ sandbox.bk

# Verify MD5 sum
md5sum sandbox/disk.img 
4976347006df34843d29c939b5fc3742  sandbox/disk.img
md5sum sandbox.bk/disk.img 
4976347006df34843d29c939b5fc3742  sandbox.bk/disk.img

# Create a 5Gb temp file
dd if=/dev/zero of=Tempfile bs=1024 count=5000000

# Append it to the existing image
cat Tempfile >> disk.img
rm Tempfile

# Resize the partition
resize2fs -f disk.img

# Check partition & start domU
fsck.ext3 disk.img
xm create -c sandbox.cfg