15

I deleted a 2.3GB log file on my Ubuntu server, and df doesn't seem to be picking up the change. Is there typically a delay before df can detect that a large file has been deleted?

4 Answers 4

24

It sounds like the file is still open by some process. You'll need to restart that service for the disk space to be freed.

8
  • 4
    Particularly likely to be true for log files. Many programs open their log filse when they start and don't close them until exit.
    – mattdm
    Feb 1, 2011 at 4:19
  • 2
    And you can find out if it's still in use and by whom using lsof
    – Joris
    Feb 1, 2011 at 6:00
  • Great question and great answer. I've been wondering this for some time now. Also, you may be able to get it to close its file handle by sending it a SIGHUP. For example, if process 12345 has a "deleted" file open, then sudo kill -HUP 12345 may get that process to close it. (It depends, of course, on how that process handles a SIGHUP signal. But lots of daemon oriented files will close and reopen file handles when they receive a SIGHUP.) Sep 18, 2012 at 18:56
  • I thought we cannot delete opened files ! Nov 10, 2015 at 13:19
  • 2
    @AshishKarpe No, you can delete an opened file, but the process with it open will keep the content of the file on disk. The file is now invisible to other processes, due to being unreferenced by any existing filename, but the process which had it open can still read and write it. Once that process closes the file, the content will be deleted, reclaiming the disk space. Dec 14, 2015 at 17:28
4

If the filesystem was out of space you could be running into the reserved space on the filesystem. The ext2/3/4 filesystems have some reserved space set aside for root. By default this is 5%. So if it was full and 2.3GB is less than 5% of the space on the drive the filesystem will still appear to be full.

In this situation you have two choices. To continue to free up space to the point that you have usable free space or modify the amount of space the filesystem has reserved. To modify the amount of reserved space use the tune2fs -m 0 /dev/sda1 replacing the 0 with the percentage of reserved space you wish to have and /dev/sda1 with the appropriate device.

See the accepted answer to this question for more details.

1

Not long. Chances are high that the file is simply still being used. There won't be disk space release till you terminate corresponding process(es).

-1

Also check your .trash directory.

2
  • where is this .trash directory ? Nov 10, 2015 at 13:17
  • On ubuntu 14.04 I see I have a ~/.local/share/Trash, which is full of junk I've deleted in Nautilus. Dec 14, 2015 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .