Greetings all, For a file that is open, but deleted, is there a way to create a new filename for it given either the file descriptor from the process or the inode?
Thus far, my Google searches suggest the answer is "no". But I find that hard to believe. In the example below, I would like to create a new filename for /tmp/zfoo.txt, which I have deleted. I have the original filename, the inode, and the file descriptor from the process. In fact, I can even create a copy using 'tail'. I was just wondering if I could create a new filename with that inode number. $ { while : ; do date ; sleep 1 ; done > /tmp/zfoo.txt ; } & [1] 29573 $ pid=$(jobs -p) $ ls -la /tmp/zfoo.txt -rw-rw-r-- 1 rwcitek rwcitek 29 Nov 13 01:16 /tmp/zfoo.txt $ ls -i /tmp/zfoo.txt 573463 /tmp/zfoo.txt $ sleep 5 $ head -3 /tmp/zfoo.txt | cat -n 1 Thu Nov 13 01:16:31 EST 2014 2 Thu Nov 13 01:16:32 EST 2014 3 Thu Nov 13 01:16:33 EST 2014 $ tail -3 /tmp/zfoo.txt | cat -n ; sleep 2 ; echo ; tail -3 /tmp/zfoo.txt | cat -n 1 Thu Nov 13 01:16:33 EST 2014 2 Thu Nov 13 01:16:34 EST 2014 3 Thu Nov 13 01:16:35 EST 2014 1 Thu Nov 13 01:16:35 EST 2014 2 Thu Nov 13 01:16:36 EST 2014 3 Thu Nov 13 01:16:37 EST 2014 $ lsof /tmp/zfoo.txt COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 29573 rwcitek 1w REG 202,2 232 573463 /tmp/zfoo.txt $ \rm /tmp/zfoo.txt $ touch /tmp/zfoo.txt $ ls -la /tmp/zfoo.txt -rw-rw-r-- 1 rwcitek rwcitek 0 Nov 13 01:16 /tmp/zfoo.txt $ lsof /tmp/zfoo.txt $ lsof +L1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME bash 29573 rwcitek 1w REG 202,2 232 0 573463 /tmp/zfoo.txt (deleted) sleep 29604 rwcitek 1w REG 202,2 232 0 573463 /tmp/zfoo.txt (deleted) $ echo ${pid} 29573 $ head -3 /proc/${pid}/fd/1 | cat -n 1 Thu Nov 13 01:16:31 EST 2014 2 Thu Nov 13 01:16:32 EST 2014 3 Thu Nov 13 01:16:33 EST 2014 $ tail -3 /proc/${pid}/fd/1 | cat -n 1 Thu Nov 13 01:16:36 EST 2014 2 Thu Nov 13 01:16:37 EST 2014 3 Thu Nov 13 01:16:38 EST 2014 $ tail -n +1 -f /proc/${pid}/fd/1 > /tmp/zfoo.new.txt & Regards, - Robert _______________________________________________ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug