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

Kill Mac OS disk warning notification

Tagged kill, notification, osx, disk, disk space  Languages bash

This explains how you can kill the Mac OS disk warning notification that reminds you that you need to buy more overpriced hardware with more disk space from Apple even if you have plenty of disk space left on your brand new Apple crippleware computer.

Before Mac OS Mojave this used to work:

# 1 = 1Gb
$ defaults write com.apple.diskspaced minFreeSpace 1
$ killall diskspaced

Setting minFreeSpace to 1 prevents the notification from showing up every second, if free disk space is above 1 Gb.

With Mojave we have to completely disable the agent:

$ launchctl unload -w /System/Library/LaunchAgents/com.apple.diskspaced.plist

Tested on Mac OS Mojave and iMac crippleware.