Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link to a specific inode

Tags:

linux

inode

ln

lsof

I have a file that was deleted, but is still held open my a program. I found the inode number using lsof. How can I create a hard link back to that inode?

Any code helps, but Perl would be handy.

like image 965
Jeff Ferland Avatar asked Jul 24 '09 15:07

Jeff Ferland


2 Answers

Copy from /proc/pid/fd/file descriptor

Use lsof to find the pid and the file descriptor.

like image 180
moonshadow Avatar answered Nov 15 '22 10:11

moonshadow


on EXT filesystem you can use debugfs command to recreate the link like :

debugfs -w /dev/mapper/vg0-root -R 'link <16> myfile'

Which will create a "file" named myfile and pointing to inode 16.

like image 40
Poulpatine Avatar answered Nov 15 '22 11:11

Poulpatine