
Quick Linux Tip #13 Question: I deleted a log file but the app is still writing to it. Can I recover it?
Try: sudo ls -la /proc/1234/fd/
Info: Linux keeps deleted files on disk while any process has them open. /proc/PID/fd/ shows file descriptors with (deleted) marker for such files. Copy from there to recover.
Examples:
$ sudo lsof +L1 # Find all deleted-but-open files
$ sudo ls -la /proc/$(pgrep nginx)/fd/
$ sudo cp /proc/1234/fd/1 recovered.log
Note: Two steps: identify FD number, then copy. Works only while process runs. Restarting the process = data lost forever.
Follow r/LinuxTeck for more #LinuxTips