I started downloading a big file and accidently deleted it a while ago. I know how to get its current contents by cping /proc/<pid>/fd/<fd> but since the download is still in progress it'll be incomplete at the time I copy it someplace else.

Can I somehow salvage the file right at the moment the download finishes but before the downloader closes the file and I lose it for good?


Using tail in follow mode should allow you to do what you want.

tail -n +0 -f /proc/<pid>/fd/<fd> > abc.deleted

I just did a quick test and it seems to work here. You did not mention whether your file was a binary file or not. My main concern is that it may not copy from the start of file but the -n +0 argument should do that even for binary files.

The tail command may not terminate at the end of the download so you will need to terminate it yourself.

  • Was about to post the same thing. Appears to work fine for binary files (+1 works too). – Mat Feb 26 '12 at 16:48
  • Sometimes, we're happy doing really weird stuff – Coren Feb 26 '12 at 18:38

Actually I had another thought. If you use another command to read /proc/<pid>/fd/<fd> and keep that program running then when you download completes you can copy it from the appropriate /proc/<pid2>/fd/<fd2> file of the second command.

Just try

less /proc/<pid>/fd/<fd>

in a separate shell. Looking at the /proc entry for the less command should show you your deleted file.

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.