Troubleshooting High Disk Space Utilisation – Linux

Categories

Troubleshooting High Disk Space Utilisation – Linux

You are here:

Introduction

A full disk can affect your Linux server in many ways, services can stop working or working as intended or in extreme cases the server may become unresponsive.  This article covers how to determine the status of your disk space and how to easily find any large folders and files on your system.

Commands in this article are to be run using an ssh or terminal connection to your server.

See the free space of your disks

Once you have ssh into your server, you can see the overall disk usage by running the following:

df -h

Example output

# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 4.0K 3.9G 1% /dev/shm
tmpfs 3.9G 9.2M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda3 92G 91G 1G 99% /
/dev/sda1 950M 130M 820M 14% /boot
/dev/loop0 3.9G 9.1M 3.7G 1% /tmp
tmpfs 783M 0 783M 0% /run/user/0

This example shows amongst other filesystems that the root (/) filesystem is 99% used.

See directory size

Once you have determined that you are running out of space, you will want to find where the space is being used. Run the du command (as root) to check folder sizes:

du -hsx /*

Example output

# du -hsx /*
15G /backup
0 /bin
98M /boot
0 /dev
69M /etc
14G /home
0 /lib
0 /lib64
0 /media
0 /mnt
602M /opt
0 /proc
33M /root
9.2M /run
0 /sbin
0 /srv
0 /sys
1000K /tmp
80G /usr
3.9G /var

As you can see, /usr is 80GB in size.

Using the example, you can then go further into /usr to see which subdirectory is using the most space

# du -hsx /usr/*
403M /usr/bin
0 /usr/etc
0 /usr/games
33M /usr/include
890M /usr/lib
586M /usr/lib64
86M /usr/libexec
2.8G /usr/local
595M /usr/sbin
499M /usr/share
0 /usr/src
75G /usr/tmp
195M /usr/tmpDSK

This shows /usr/tmp as 75G. You would then run du on /usr/tmp and so on until you pinpoint the directory or files that are using up the disk space.

Find Command

The find command is useful when you want to search through directory trees on a hard drive.

You can locate files and / or directories based on some user-specified criteria and you can even run a specific action on these files / directories using a program such as xargs.

Use find followed by the path to show everything (files, folders and more) under that path.

find /home/

Find something by type

By using the -type option you can specify files (-type f), directories (-type d), or even symbolic links (-type l)

find /home/ -type d

This would find all directories under home.

Find a file by size

You can search for a file by a specific size but in most situations you won’t know the exact size, so by adding a + means this size or larger, and a – means this size or smaller.

Find a file greater than 1 Gigabyte

find /home/ -type f -size +1G

You can specify sizes in Kilobytes (k) and Megabyte (M)

find /home/ -type f -size +200M

To find files less than a specific size, use – instead

find /home/ -type f -size -50M

You can also combine the two to find files in between a size range

find /home/ -type f -size +700M -size -900M
Previous Testing your hard drives with SMART – Linux
Next Troubleshooting Network issues using MTR
Table of Contents