2

Is there a way to restore/recover a removed file when it's still in use?

4

On Linux at least, you can access all files which a process still has open, in /proc/${pid}/fd:

$ echo Test > removeme
$ sleep 1200 < removeme &
[1] 21954
$ rm removeme
$ ls -l /proc/21954/fd
total 0
lr-x------. 1 skitt skitt 64 Aug 13 17:14 0 -> '/home/skitt/tmp/removeme (deleted)'
lrwx------. 1 skitt skitt 64 Aug 13 17:14 1 -> /dev/pts/7
lrwx------. 1 skitt skitt 64 Aug 13 17:14 2 -> /dev/pts/7
$ cat /proc/21954/fd/0
Test

You can cp the corresponding file to recover it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.