14

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?

dan
  • 847
  • 2
  • 9
  • 11

4 Answers4

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.

toppledwagon
  • 4,245
  • 25
  • 15
  • 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 01 '11 at 04:19
  • 2
    And you can find out if it's still in use and by whom using lsof – Joris Feb 01 '11 at 06: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.) – Mark E. Haase Sep 18 '12 at 18:56
  • I thought we cannot delete opened files ! – Ashish Karpe Nov 10 '15 at 13:19
  • In my case i got 18Gb logs in /var/log/apache2 I couldn't retrieve my free space until .. stopped apache :) I restarted apache and my free space returned. –  Nov 25 '15 at 20:37
  • Common examples of this: If you have a nautilus or terminal window open in that directory. – Jonathan Hartley Dec 14 '15 at 17:25
  • 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. – Jonathan Hartley Dec 14 '15 at 17:28
  • use `lsof +L1` to see the deleted-but-open files – törzsmókus Jun 14 '23 at 15:06
3

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.

3dinfluence
  • 12,449
  • 2
  • 28
  • 41
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).

poige
  • 9,448
  • 2
  • 25
  • 52
-1

Also check your .trash directory.

JakeRobinson
  • 2,904
  • 18
  • 26