Skip to content

Find Deleted Files in Use Linux: Reclaim Disk Space

How to Find Processes Using Deleted Files on Linux

If you delete a large log file on a Linux server but disk usage does not decrease, a running process may still be holding the file open. Learning how to find deleted files in use Linux systems can help you identify the process responsible and reclaim disk space without unnecessarily rebooting the server.

This situation commonly occurs when applications, web servers, databases, or background services continue writing to a log file after it has been deleted. Linux removes a file’s directory entry when it is unlinked, but the file’s data remains allocated while a process still holds an open reference to it.

In this guide, you will learn how to identify deleted-but-open files with lsof +L1, inspect file descriptors under /proc, investigate disk usage discrepancies, and safely reclaim space by restarting or reloading the appropriate service.

Why Does Linux Keep Deleted Files Open?

On Linux, deleting a file does not necessarily free its disk space immediately. The rm command removes the filename from the directory, but the underlying file data remains available to processes that already have the file open.

Disk space is generally reclaimed when the last open reference to the deleted file is closed, provided no other filesystem references are keeping its storage allocated.

For example, a web server may be writing to /var/log/nginx/access.log. If someone deletes that file while Nginx still has it open, Nginx can continue writing to the unlinked file. The filename disappears, but the storage may remain occupied.

Common causes include:

  • Deleting large application or web server logs while the service is running.
  • Removing log files without reloading or restarting the application.
  • Applications that keep file descriptors open for long periods.
  • Custom logging scripts that delete files instead of using log rotation.
  • Background processes that write to temporary files after their directory entries have been removed.

This is different from a filesystem cache issue. When a process holds a deleted file open, the allocated blocks can remain in use even though the file no longer appears in its original directory.

1. Confirm That Disk Space Is Not Being Reclaimed

Start by checking filesystem usage:

df -h

This shows the total, used, and available space on mounted filesystems.

Next, inspect directory-level usage:

sudo du -xhd1 /var 2>/dev/null

The -x option keeps the scan on the same filesystem, while -d1 limits the output to one directory level. GNU du supports these options on common Linux distributions; on systems with a different implementation, consult du --help.

Compare the output of df and du.

  • df reports filesystem-level space usage.
  • du estimates space occupied by files and directories that it can traverse.
  • A large difference can indicate deleted-but-open files, but it can also result from filesystem metadata, reserved blocks, snapshots, mount points, or other filesystem-specific behavior.

For example, if df -h shows that /var is nearly full while du reports relatively little visible data, investigate deleted open files before removing more files.

Important: Do not assume that every df and du discrepancy is caused by open deleted files. Use the following checks to confirm the cause.

2. Find Deleted Files Using lsof +L1

The lsof utility lists open files associated with running processes. Its +L1 option selects open files whose link count is less than one, which is commonly used to find deleted-but-open files on Linux.

Check whether lsof is installed:

command -v lsof

If it is missing, install it using your distribution’s package manager.

On Ubuntu or Debian:

sudo apt update
sudo apt install lsof

On AlmaLinux, Rocky Linux, or other compatible RHEL-based systems:

sudo dnf install lsof

Run the main diagnostic command:

sudo lsof +L1

Example output:

COMMAND   PID  USER   FD   TYPE DEVICE  SIZE/OFF NLINK  NODE NAME
nginx    1842  root   12w  REG  253,0   524288000     0  8123 /var/log/nginx/access.log (deleted)
python   2917  app    5w   REG  253,0   1073741824     0  9341 /tmp/worker.log (deleted)

These values are illustrative. Your output will depend on the processes and files open on your server.

The important columns are:

Column Meaning
COMMAND Process name
PID Process ID
USER Process owner
FD File descriptor and access mode
SIZE/OFF File size or current offset, depending on file type
NLINK Number of directory links
NAME File path, often marked (deleted)

An NLINK value of 0 and a filename ending in (deleted) are strong indicators of an unlinked file that remains open.

Show only the relevant output

To focus on entries marked as deleted:

sudo lsof +L1 | grep '(deleted)'

To display the largest reported entries first, you can use:

sudo lsof -nP +L1

The -nP options disable hostname and service-name resolution, which can make output faster and easier to read. They do not sort the files by size.

For a busy production server, review the results carefully. A process may have multiple deleted file descriptors, and the reported size does not always equal the exact number of filesystem blocks that will be reclaimed when the descriptor closes.

3. Identify the Process Holding the Deleted File

Once you find a deleted file, identify the process that owns its file descriptor.

For example, suppose lsof reports PID 1842 holding a deleted Nginx log file.

Inspect the process:

ps -fp 1842

Check its executable:

sudo readlink -f /proc/1842/exe

Inspect its command line:

sudo tr '\0' ' ' < /proc/1842/cmdline
echo

These commands help confirm whether the process belongs to Nginx, Apache, PHP-FPM, a database, a Python application, or another service.

Next, inspect the process’s open file descriptors:

sudo ls -l /proc/1842/fd

Replace 1842 with the actual PID from your output.

You may see a symbolic link similar to:

12 -> /var/log/nginx/access.log (deleted)

This confirms that the process still has an open descriptor referencing the deleted file.

Check the file descriptor directly

If the file descriptor number is 12, inspect it with:

sudo readlink /proc/1842/fd/12

You can also inspect the descriptor’s metadata:

sudo cat /proc/1842/fdinfo/12

The /proc/PID/fd directory exposes a process’s open file descriptors. Access is subject to permissions and system security settings, so use sudo where appropriate.

Caution: Do not write to, truncate, or otherwise modify /proc/PID/fd/12 simply to reclaim disk space. That descriptor may belong to a critical log, application data file, or database process. Closing it through the appropriate application or service lifecycle is generally safer.

4. Estimate How Much Disk Space Can Be Reclaimed

The SIZE/OFF column from lsof can help identify potentially large deleted files.

For example, a file reported as approximately 1 GiB may be contributing significantly to filesystem usage. However, the displayed size is not always equal to the number of allocated disk blocks, particularly for sparse files or files with filesystem-specific allocation behavior.

To inspect an open file’s metadata, use its descriptor path:

sudo stat /proc/1842/fd/12

Replace the PID and descriptor number with the values from your system.

Review the file size and block allocation information where available. The filesystem may reclaim a different amount of space than the logical file size suggests.

To list deleted open files with their reported sizes, you can use:

sudo lsof -nP +L1

If multiple processes hold descriptors for the same underlying file, do not add the displayed sizes blindly. The same file may appear more than once, and space is generally reclaimed only after all relevant references have been closed.

5. Reclaim Disk Space Safely

The safest fix is usually to make the owning application close the deleted file descriptor. The correct method depends on the process.

Before taking action:

  1. Identify the process and confirm its role.
  2. Determine whether the file is a log, temporary file, or application data.
  3. Check the service’s supported reload or reopen procedure.
  4. Confirm that the application can continue safely without the old descriptor.
  5. Avoid forcefully terminating critical processes unless you understand the impact.

Option A: Reload or signal a service to reopen logs

Some services support reopening log files without a full restart. This is particularly useful for web servers and applications with log-reopen support.

For Nginx, if the service is healthy and the service manager is configured normally, you can request a log reopen using:

sudo nginx -s reopen

Alternatively, on a system using systemd:

sudo systemctl kill --signal=USR1 nginx

Use the appropriate method for your installation and verify that the signal is supported by the running service. Nginx commonly uses USR1 to reopen log files.

However, reopening logs does not guarantee that every deleted descriptor will close. If the application has a separate file handle or a different logging configuration, investigate that specific descriptor.

Option B: Restart the affected service

If the application cannot reopen the file, a controlled service restart may close the old descriptor and allow the filesystem to reclaim the space.

For Nginx:

sudo systemctl restart nginx

For Apache on Ubuntu or Debian, the service is commonly named apache2:

sudo systemctl restart apache2

For Apache on many RHEL-based distributions, the service is commonly named httpd:

sudo systemctl restart httpd

Do not run every example. Restart only the service you have identified, using the correct service name for your system.

A restart can interrupt active requests, connections, or background jobs. For databases and other stateful applications, follow the vendor’s supported maintenance procedure rather than assuming a restart is harmless.

Option C: Restart a custom application carefully

If the process belongs to a custom application, first identify how it is managed:

ps -fp 2917

If it is a systemd service, inspect the service unit and its status:

sudo systemctl status your-app.service

Replace your-app.service with the actual service name.

If the application supports log reopening, use that mechanism first. Otherwise, schedule a controlled restart when the application’s workload and recovery requirements allow it.

Avoid blindly killing a process by PID. A PID may be reused, and a forced termination can cause downtime or data loss.

Option D: Handle a process that cannot be restarted immediately

If restarting the process is not currently possible, consider whether the application provides a safe way to close or reopen the relevant file descriptor.

Do not assume that manually closing an arbitrary descriptor is safe. The descriptor number may be used by the application’s logging system or other internal logic. Closing it externally can lead to unexpected behavior, and writing to the descriptor may overwrite data or fail to release the intended storage.

If the application has no supported mechanism, arrange a maintenance window or consult its documentation before taking more invasive action.

6. Verify That Disk Space Has Been Reclaimed

After the service has closed the old file descriptor, check filesystem usage again:

df -h

Repeat the deleted-file search:

sudo lsof +L1

If the relevant entry no longer appears and the filesystem reports more available space, the cleanup likely succeeded.

Also check the application status:

sudo systemctl status nginx

Replace nginx with the affected service name.

For a custom application, verify its service health, logs, and expected behavior.

If disk usage has not changed, consider these possibilities:

  • Another process still holds the same deleted file open.
  • Multiple deleted files are consuming space.
  • The deleted file is on a different filesystem.
  • A different directory or application is consuming the disk space.
  • The filesystem uses snapshots, reserved blocks, or other allocation mechanisms.
  • The process reopened a new log file but still holds another deleted descriptor.

Repeat the investigation instead of restarting unrelated services.

7. Prevent Deleted-File Disk Usage Problems

The best long-term solution is to manage logs and temporary files correctly instead of relying on manual deletion.

Configure log rotation

Use logrotate or the logging mechanism supported by your application. Proper rotation can create a new log file and arrange for the application to reopen it, preventing old log descriptors from retaining unnecessary space.

For example, a typical logrotate configuration may use a postrotate action to notify a service to reopen its logs. The correct command depends on the application, so use the service’s documented method.

Monitor disk usage

Check filesystem capacity regularly:

df -h

Inspect major directories:

sudo du -xhd1 /var 2>/dev/null

For automated monitoring, configure alerts for filesystem utilization and inode usage. This helps detect problems before the disk becomes completely full.

Avoid deleting active log files manually

If a log file is growing too quickly, investigate why it is growing and configure rotation or retention. Deleting the file directly may hide the symptom while leaving the process writing to the unlinked file.

Review application logging behavior

Applications should use supported log rotation, reopening, and file lifecycle mechanisms. For custom applications, make sure file descriptors are closed when files are no longer needed and that logging behavior remains safe during rotation.

Conclusion

When Linux disk usage remains high after deleting files, a process may still be holding one or more deleted files open. The lsof +L1 command is a practical starting point for finding these files, while /proc/PID/fd helps identify the process and descriptor involved.

To reclaim space safely, confirm the owning process, use its supported log-reopen mechanism where available, or perform a controlled service restart. Then verify the result with df -h and another lsof +L1 check.

For long-term prevention, configure log rotation, monitor filesystem capacity, and avoid manually deleting active log files. These practices help maintain disk availability and reduce unnecessary service interruptions on Linux VPS and dedicated servers.

If you need a Linux environment for server administration and troubleshooting, explore ServerNext VPS solutions and choose a setup suitable for your workload.