Bash: No space left on device

If you get this error on your Linux web server: -bash: No space left on device , that means there is no space left on some of your Linux partitions and you need to free up disk space asap.

When you are running out of space on your server many system services will start failing. On this post we will analyze the main causes of this ‘bash: no space left on device’ error.

Fixing Bash: No space left on device error

There are two main causes for this error:

1- You exhausted all available space by accumulating large files.

cPanel and Linux servers often generate lot of errors logs, this logs can grow really large in some cases, wasting GBs of useful disk space. You can delete user’s error_logs from inside public_html directory of each webiste by running this commands:

rm /home/*/public_html/error_log -fv
rm /home/*/public_html/*/error_log -fv
rm /home/*/public_html/*/*/error_log -fv
rm /home/*/public_html/*/*/*/error_log -fv

Or as Ivan suggested above:

find /home -type f -name "error_log" -size +10M -delete

“Finds them in all subdirectories, you can specify the size while also going quicker through them than using plain rm.”

Removing Apache logs can also be an useful way to save disk space when you are out of it. Try removing Apache logs if you don’t need them:

rm -fv /usr/local/apache/logs/*

For advanced ways to free disk space on cPanel we recommend you reading this post, where we fully explain everything regarding how to free up disk space on cPanel servers

2- You ran out of inodes, type this command to check if this is the reason:

df -i

If you see something like this:

Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 1420790 1420790 0 100% /

Then you definitely ran out of inodes . The best way to fix this is to free inodes on your server.

This ‘bash: no space left on device’ error is often caused by way too many php session files.

PHP session files are often located at:

/var/lib/php/sessions

However, the location of your php session files depends on your php.ini session handler path, this is defined at your general php.ini file. Let’s ensure you are removing files from the right location. To locate your php.ini file:

find / -name php .ini

On CentOS it’s usually located at /etc/php.ini. Let’s see what’s the session save path to find out where are your php session files stored:

grep session.save_path /etc/php.ini

If you get something like this, then your seession save path is: /var/lib/php/session

session.save_path = "/var/lib/php/session"

You can try to remove the contents of the specified folder:

rm /var/lib/php/session/* -fvR

After this, all your php sessions should be removed.

However, if there are too many files inside the directory, rm command will not work as expected, you can instead use find command and run -exec rm against each element using a quick script like this to handle this bash script to remove php session files:

find /var/lib/php/sessions -type f -cmin +24 -name "sess_*" -exec rm -f {} \;

Conclusion

At this time your problem should be fixed, now you know how to fix bash: no space left on device on your Linux box.  You can also set a cronjob to have your php session files deleted after certain amount of time (days or weeks).

About the Author: Martin Keler

2 Comments

  1. First one can probably be replaced with something like:

    # Show all error_log files larger than 10MB
    find /home -type f -name “error_log” -size +10M -ls

    # Delete them

    find /home -type f -name “error_log” -size +10M -delete

    Finds them in all subdirectories, you can specify the size while also going quicker through them than using plain rm. Although, that’s just my experience.

Leave a Reply

Your email address will not be published. Required fields are marked *