A common technique in content management is for a web browser to download to a temporary file, then rename the temporary file only after the download finishes & it has permission to copy it. If the download fails or of the content is copy protected, the browser deletes the temporary when it finishes.
You can copy the file before it's deleted, but there's no way with the traditional cat & cp programs to get the complete file. The cat & cp programs exit when they hit the end of the file. Fortunately for Linux, once you have a file handle open, the file handle can still read to the end of the file after the file has been deleted. The rm & unlink commands are exceptions to the rule of not being able to remove something that's still in use.
After years of using a custom program to open a file & wait for new output indefinitely, the lion kingdom finally found a variant of the tail program which does it.
tail -n +0 -f
It just outputs all the data starting from line 0 & waits for new output. This technique can't undelete files, of course.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.