Linux 任务挂起数据被误删除时,可在/proc/任务PID/fd/下进行恢复
操作步骤如下:
john@u:~$ ls --help >ls.txt #创建一个测试文本
john@u:~$ ls
ls.txt my_backup shell test
john@u:~$ more ls.txt #进行分页查看,翻下一页时 Ctrl+Z 退出
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
--More--(20%)
[1]+ Stopped more ls.txt
john@u:~$ jobs #查看后台运行任务
[1]+ Stopped more ls.txt
john@u:~$ rm ls.txt #删除测试文件
john@u:~$ ls
my_backup shell test
john@u:~$ ps aux | grep ls.txt
john 1161 0.0 0.3 3900 836 pts/0 T 15:50 0:00 more ls.txt
john@u:~$ ls -l /proc/1161/fd/ #根据 ps aux 显示内容得知 ls.txt 被 pid 1161 占用
total 0
lrwx------ 1 john john 64 Nov 6 15:55 0 -> /dev/pts/0
lrwx------ 1 john john 64 Nov 6 15:55 1 -> /dev/pts/0
lrwx------ 1 john john 64 Nov 6 15:52 2 -> /dev/pts/0
lr-x------ 1 john john 64 Nov 6 15:55 3 -> /home/john/ls.txt (deleted)
john@u:~$ cp /proc/1161/fd/3 ~/ls.txt.saved #将文件复制到 ~/目录重命名保存即可。
john@u:~$ ls
ls.txt.saved my_backup shell test
参考文章: http://www.jb51.net/LINUXjishu/64736.html