Best way to free disk space from deleted files that are held open

As others have said <code>lsof</code> can be used to list all the deleted files which are still on disk due to open file descriptors. However, this may be a very long list. Here is a command which lists these files sorted by ascending size in bytes:
lsof -F sn0 | tr -d '\000' | grep deleted | sed 's/^[a-z]*\([0-9]*\)n/\1 /' | sort -n

If some files are deleted but still used by some process then it's space will not be released. In this case either restart a process that is using the file or nullify the file. Its always good practice to null such files instead of deleting them. To find deleted files but are still in use by some process

lsof +L1

it will give process id and file descriptor. To null deleted file by file descriptor
echo "" > /proc/$pid/fd/$fd

Comments powered by CComment