Recover deleted file that is currently being written to

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.


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.