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.
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.
Copy from /proc/pid/fd/file descriptor
Use lsof to find the pid and the file descriptor.
cp
copies the content of the deleted file to a new file. It does not link to the original inode. –
Ljoka truncate
— unix.stackexchange.com/q/61820 – –
Sequential 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.
link
command does not increase the inode's reference count. So in fact the file could be lost right after the program closes the file descriptor and the reference count of the inode decreases to zero. Unfortunately I do not know a simple reliable way how to change the inode's reference count. --- Also a complete answer should show how to get the inode number: stat -L /proc/PID/fd/FILE_DESCRIPTOR
(or ls -Li
). –
Ljoka © 2022 - 2024 — McMap. All rights reserved.