Differences

This shows you the differences between two versions of the page.

Link to this comparison view

troubleshooting:df-and-du-show-different-usage [2016-08-09 18:43:25] (current)
shaun.reitan created
Line 1: Line 1:
 +====== Linux command df shows different usage than du ======
  
 +There are times when the du and df commands can show different disk usage stats.  The usual reason for this is that a running process still has a file that was removed open. This causes df to still report that space as used. The solution to this issue is to reload or restart that service so that it closes that file handle.
 +
 +lsof is a tool that can be used to find processes holding onto files. If you do not have lsof installed, you will need to install it using your package manager. Examples of how to do this are below.
 +
 +<code console>
 +# Debian and Ubuntu
 +apt-get install lsof
 +
 +# CentOS, RHEL, and Fedora
 +yum install lsof
 +</code>
 +
 +Next we want to use lsof to find the process
 +
 +<code console>
 +lsof | grep deleted
 +</code>
 +
 +If you get any output changes are it looks something like this.
 +
 +<code console>
 +httpd     32617    nobody  106w      REG        9,4 1835222944     688166 /var/log/apache/awstats_log (deleted)
 +</code>
 +
 +In this case, the process httpd is whats holding onto an 18GB file. You can either kill that process, or issue a restart using init.d or systemctl
 +
 +<code console>
 +# systemctl systems
 +systemctl restart httpd
 +
 +# Older init.d systems
 +service httpd restart
 +
 +# Even older systems
 +/etc/init.d/httpd restart
 +</code>
 +
 +If the process doesn't have an init script you will need to restart it another way, or as a last resort kill the process. The second column output from lsof is the process id.
 +
 +<code console>
 +kill -9 32617
 +</code>
 +
 +Now when running df again you should now see df reporting correctly.