> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/guides-for-server-management/check-free-disk-space-in-linux.md).

# Check free disk space in Linux

***

Running out of disk space on a server is easy, and it can have serious consequences—for example, you might end up with corrupted MySQL tables.

Inodes can also be exhausted. If you’re not sure why you’re using so many inodes, it may be because an application is creating a lot of temporary files that aren’t cleaned up. A common example is PHP session files when the garbage collector (GC) isn’t clearing them properly.

Below is an example script that can be run from crontab. It will email you when disk space or inode usage exceeds 90%.

Please note that to send outgoing email, you need to set up a working SMTP server, such as Postfix. See [Sending email from your server using Postfix](/products/compute/guides-for-server-management/sending-email-from-your-server-using-postfix.md) for instructions on how to set up Postfix.

{% code title="monitor-disk-usage.sh" %}

```bash
#!/bin/bash
# A small shell script to check disk and inode usage
    
FROM_EMAIL=some@email.com # The sender of the alert email
TO_EMAIL=some@example.com # The recipient of the alert email
LIMIT=90 # Percent (when to send email)
HOSTNAME=`hostname -f`
    
# Check all mount points
for i in `df |awk '{print $5}'|grep -v Use|sed 's/\%//'` ; do
        if [ $i -gt $LIMIT ];then
                (/usr/bin/printf "From: $FROM_EMAIL\nTo: $TO_EMAIL\nSubject: Disk alert on $HOSTNAME\n\n" ; echo "Disk is $i percent full") | /usr/sbin/sendmail -f$FROM_EMAIL $TO_EMAIL
        fi
done
for i in `df -x vfat -x fat -i |awk '{print $5}'|grep -v Use|sed 's/\%//'` ; do
        if [ $i -gt $LIMIT ];then
                (/usr/bin/printf "From: $FROM_EMAIL\nTo: $TO_EMAIL\nSubject: Disk alert on $HOSTNAME\n\n" ; echo "Inode use $i percent") | /usr/sbin/sendmail -f$FROM_EMAIL $TO_EMAIL
        fi
done
```

{% endcode %}

Before running the script, you need to make it executable with `chmod +x monitor-disk-usage.sh`.

## Crontab example

Edit your crontab using `crontab -e`. To run the script every 6th hour, add the following line (change `/path/to/script` to the path where the script is stored on the server).

```
0 */6 * * * /path/to/script/monitor-disk-usage.sh
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.glesys.com/products/compute/guides-for-server-management/check-free-disk-space-in-linux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
