20
5
How can one restore a file that has been deleted but is still open by a process?
The blog post "Restoring files from /proc
" explains how to do this on Linux:
- Use
lsof
(e.g.,lsof -c name
) to find all files currently open for the given process (whose name starts withname
). From the output, you learn the process'spid
and the file descriptor (fd
) of the file you are looking for. - Use
cp /proc/<pid>/fd/<fd>
/tmp/restored-file` to make a copy.
The first step works one-to-one on OS X, too. However, step 2 seems more complicated. Is there a similar feature on OS X?
(I tried /dev/fd
but in my case, it did not contain the PID/FD of my process/file.)
1
Testdisk: http://www.cgsecurity.org/wiki/TestDisk; Photorec: http://www.cgsecurity.org/wiki/PhotoRec - Both of these are better than most other file recovery tools I've used. Photorec won't necessarily recover metadata, but the data's there. This is probably too late, but you could also run one of these off a flash drive before rebooting if you think the risk of something else overwriting the sectors is low.
– Nick – 2012-06-21T17:57:23.407Thanks, @Stephanie, very kind of you, for sharing the approach and the tools. I was asking the question out of interest, to learn more about OS X, so fortunately no urgency involved (but I appreciate your timely reply!). – Hbf – 2012-06-22T16:14:59.323