Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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.

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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