Technology Encyclopedia Home >Why is the hard disk space not released when deleting files on a Linux server?

Why is the hard disk space not released when deleting files on a Linux server?

When you delete files on a Linux server, the disk space may not be immediately released because the files might still be held open by running processes. In Linux, deleting a file (using rm) only removes its directory entry, but if a process still has the file open, the inode and data blocks remain allocated until the process closes the file.

Example:

  1. A log file (/var/log/app.log) is being written to by a service.
  2. You run rm /var/log/app.log, but the service continues writing to the file descriptor it already opened.
  3. The disk space is not freed because the file's data blocks are still in use by the process.

To check for such files, use:

lsof | grep deleted

This lists files deleted but still held open by processes. To free the space, restart the process or service using the file.

For log rotation and disk management, Tencent Cloud provides Cloud Log Service (CLS) to efficiently collect, store, and analyze logs, avoiding manual file deletion issues. Additionally, Tencent Cloud File Storage (CFS) and Cloud Block Storage (CBS) offer scalable storage solutions with automated management features.