找回误删的nginx配置文件

一不小心执行了这条命令sudo rm /usr/local/lighthouse/softwares/nginx/conf/nginx.conf,心里顿时很慌。查了一下资料,发现可以找回来,于是开始操作。
首先执行 sudo lsof | grep deleted,得到如下:

mariadbd   1736 13114          mysql   12u      REG              253,1         0     655396 /tmp/#655396 (deleted)
vim        4074                 root    4u      REG              253,1     16384     655382 /usr/local/lighthouse/softwares/nginx/conf/.nginx.conf.swp (deleted)

还有救。继续执行命令 sudo ls /proc/4074/fd -ilh 得到如下

total 0
52769 lrwx------ 1 root root 64 Feb 26 08:02 0 -> /dev/pts/0
52770 lrwx------ 1 root root 64 Feb 26 08:02 1 -> /dev/pts/0
52771 lrwx------ 1 root root 64 Feb 26 08:02 2 -> /dev/pts/0
423368 lrwx------ 1 root root 64 Feb 26 09:56 4 -> /usr/local/lighthouse/softwares/nginx/conf/.nginx.conf.swp (deleted)

执行命令 sudo cp /proc/4074/fd/4 /usr/local/lighthouse/softwares/nginx/conf/.nginx.conf.swp
成功找回中间文件,使用vim 打开,然后保存,成功找回nginx配置文件。