In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use the Lsof command in Linux to restore mistakenly deleted files? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Principle: the directory and name of the process are saved under the / proc partition of the Linux system, including fd (file descriptor) and its subdirectory (link to the file opened by the process), then if you delete a file, there is also a reference to inode: / proc/ process number / fd/ file descriptor. As long as we know the process pid and the file descriptor FD that currently open the file, we can use the lsof tool to list the files opened by the process.
First, filter out the main controls of the ls manual and redirect it to the file ls.txt, and view it with more, and CTRL + Z pauses the viewing operation.
1: [root@localhost script] # man ls | col-b > ls.txt
2: [root@localhost script] # more ls.txt
3: LS (1) User Commands LS (1)
4:
1: 1 + Stopped more ls.txt
2: [root@localhost script] #
3: [root@localhost script] # jobs
4: 1 + Stopped more ls.txt
5:
2. Suppose the file ls.txt is deleted by mistake.
1: [root@localhost script] # rm ls.txt
2: rm: do you want to delete the general file "ls.txt"? Y
Use lsof to find process 6511 and copy and restore it, which is valid only if the file is used or called.
3: [root@localhost script] # lsof | grep ls.txt
4: more 6511 root 3r REG 253 7300 1083699 / opt/script/ls.txt (deleted)
5:
Root@localhost script # ls-l / proc/6511/fd/
2: 0 1 2 3
Root@localhost script # ls-l / proc/6511/fd/3
4: lr-x- 1 root root 64 10-30 21:21 / proc/6511/fd/3-> / opt/script/ls.txt (deleted)
5:
1: cp / proc/6511/fd/3 ls.txt.saved
This is the answer to the question about how to use the Lsof command to restore mistakenly deleted files in Linux. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.