How to undelete any open file on Linux
finalcog.com
finalcog.com
Is there some arcane unix command that allows you to do that ?
If the file is large enough there may not be enough space to do a copy, so that's why it would be nicer to actually restore that inode...
jam@jam:~$ touch z
jam@jam:~$ tail -f z
^Z
[1]+ Stopped
jam@jam:~$ rm z
jam@jam:~$ lsof | grep /home/jam/z
tail 19192 jam 3r REG 8,17 0 821339 /home/jam/z (deleted)
jam@jam:~$
The 821339 is the inode.
i.e. -> ln 821339 new-file-name
Effectively all ln does is call the 'link' system call, the paramters of 'link' are two path names on the same file system.
Alternatively, the sledgehammer method is hitting the power button: a fsck should be able to pick up the nonzero refcount and make it available in lost+found. (depending on the file system)
-# fsdb /dev/ufs/foo
> inode 424242 # inode number of the target directory
> ln 821339 myimportantfile
You might also need to do "inode 821339" and "uplink" to increment the link count. Alas, you can't do this on a live filesystem, at least not safely, and once deleted the inode will be cleared, so doing this won't get your file back. Maybe if you pull the plug and try it on an unclean filesystem?look up fsdb and friends.
cp /proc/322/fd/3 savedfile is a lot easier than fiddling around with fsdb on a mounted filesystem.