How to recover free space on deleted files without restarting the referencing processes

disk-space-utilizationsolarissolaris-10unix

When big files are deleted on a server, the files might still be referenced by processes, so the file system doesn't have more free space.

I tried to use lsof, but it seems it didn't list the deleted files. fuser -c did better work, but the list of processes is just too long to check it out for each process, especially since each process is an Oracle process.

bash-3.2# fuser -c /var
/var:      105o   29999o   20444c    3528c   27258o    7715o    3864o    3862o    2494o   18205o   17450co   17445co   14912co   14824co   14818co   14816o   14814o    8532c    8530c    7633com    7118o    6958o    6790c    6784co    6734o    6693o    6689o    6684o    6675o    6635o    6594c    6548o    6547o    6546o    6545o    6544o    6543o    6542o    6541o    6540o    6537o    6535o    6456o    6128co    6113o     335o     245co     229o     161o       8o
bash-3.2# du -hs /proc
 139T   /proc

It happens sometimes that a file gets deleted by an application or a user, e.g. a logfile and that this file is still being referenced by a process that cannot be restarted.

Are there goods methods to reclaim disk space on deleted files without restarting the process that has a reference to this deleted file?

Best Answer

find /proc/*/fd -ls 2> /dev/null | grep '(deleted)'

Find all opened file descriptors.

Grep deleted.

StdError to /dev/null

Output:

160448715    0 lrwx------   1 user      user            64 Nov 29 15:34 /proc/28680/fd/113 -> /tmp/vteT3FWPX\ (deleted)

Or you can use awk

find /proc/*/fd -ls 2> /dev/null | awk '/deleted/ {print $11}';

awk output(tested in bash Ubuntu 12.04):

/proc/28680/fd/113

Find and truncate all deleted files(tested in bash Ubuntu 12.04):

(DON'T DO THIS IF YOU DON'T KNOW WHAT YOU DO)

find /proc/*/fd -ls 2> /dev/null | awk '/deleted/ {print $11}' | xargs -p -n 1 truncate -s 0

-p prompt before execute truncate

Better way is manual truncate

Manual truncate:

: > /proc/28680/fd/113

or:

> /proc/28680/fd/113

or:

truncate -s 0 /proc/28680/fd/113

Enjoy ;)

Related Topic