Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Disk Space

show space (linux)

In most operating systems, once you run out of space, the system will crash. When you get close to running out of space, other errors will start happening. Some tasks are smart enough to check for disk space before starting and if there isnt enough, the command will fail, sometimes silently. You can view disk space in linux using the df -h command:

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           198M  1.1M  197M   1% /run
/dev/vda1        58G  7.9G   51G  14% /
tmpfs           988M     0  988M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/vda15      105M  6.1M   99M   6% /boot/efi
tmpfs           198M  4.0K  198M   1% /run/user/0
tmpfs           198M  4.0K  198M   1% /run/user/1003

Inode Consumption (linux)

You can have plenty of disk space but run out of inodes. Check with df -hi

Filesystem     Inodes IUsed IFree IUse% Mounted on
tmpfs            247K   710  247K    1% /run
/dev/vda1        7.4M  161K  7.3M    3% /
tmpfs            247K     1  247K    1% /dev/shm
tmpfs            247K     4  247K    1% /run/lock
/dev/vda15          0     0     0     - /boot/efi
tmpfs             50K    26   50K    1% /run/user/0
tmpfs             50K    25   50K    1% /run/user/1003

Once a computer is above 80% disk space usage, there will be problems. Linux computers need 20% free space at all times to help manage and organize their files and inodes. If a linux computer reaches 95% or higher on a root partition it can crash the system completely.

Disk Space Alert

#start editing
#stop editing
percent=$(df -h / | grep "$partition" | awk '{ print $5 }' | sed 's/%//g')
if ((percent > threshold))
echo "$partition at $(hostname -f) is nearly full" | mail -s "Your disk is nearly full!!!" "$mail"