Sobes.tech
Junior — Middle

Why can freeing disk space in Linux after deleting a large file take a long time or not happen immediately?

sobes.tech AI

Answer from AI

In Linux, freeing disk space after deleting a large file can be delayed if the file is still open by some process.

When a file is deleted, its name disappears from the filesystem, but the data remains on the disk until at least one process closes the file descriptor. This is because, in Linux, deleting a file means removing the link to the data, and the data is only deleted when there are no active links.

To check which processes are holding open deleted files, you can use the command:

lsof | grep deleted

If such a process is found, it can be terminated or restarted to free up space.

Thus, the delay in freeing disk space is related to the features of the filesystem and descriptor management in Linux.