不小心执行了rm -f,除了跑路,如何恢复?

每当我们在生产环境服务器上执行rm命令时,总是提心吊胆的,因为一不小心执行了误删,然后就要准备跑路了,毕竟人不是机器,更何况机器也有bug。

那么如果真的删除了不该删除的文件,比如数据库、日志或执行文件,咋办呢?
模拟场景

1.删除

误删除服务器目录/root/selenium/Spider下的MySql.Data.dll文件

不小心执行了rm -f,除了跑路,如何恢复?

2.删除

1.使用lsof命令查看当前是否有进程打开/root/selenium/Spider/MySql.Data.dll文件:

不小心执行了rm -f,除了跑路,如何恢复?

从上面可以看出,当前文件状态为已删除(deleted)。

2.查看是否存在恢复数据:

/proc/13067/fd:进程操作的文件描述符目录。

86:文件描述符。

>cat /proc/13067/fd/86

不小心执行了rm -f,除了跑路,如何恢复?

3.使用I/O重定向恢复文件:

不小心执行了rm -f,除了跑路,如何恢复?

重新运行程序:

不小心执行了rm -f,除了跑路,如何恢复?

说明恢复的文件没有问题。

刨根问底

通过前面的模拟场景演示了恢复文件的整个过程,那么原理是什么,在什么情况下,文件才是可恢复的。

在Linux系统中,每个运行中的程序都有一个宿主进程彼此隔离,以/proc/进程号来体现(Linux本质上就是一个文件系统)。

比如:ls -l /proc/13067 查看进程PID为13067的进程信息;当程序运行时,操作系统会专门开辟一块内存区域,提供给当前进程使用,对于依赖的文件,操作系统会发放一个文件描述符,以便读写文件,当我们执行 rm -f 删除文件时,其实只是删除了文件的目录索引节点,对于文件系统不可见,但是对于打开它的进程依然可见,即仍然可以使用先前发放的文件描述符读写文件,正是利用这样的原理,所以我们可以使用I/O重定向的方式来恢复文件。

总结

如果不小心误删了文件,不要着急,首先使用 lsof 查看打开该文件的进程,然后再使用 cat /proc/进程号/fd/文件描述符 查看恢复数据,最后使用I/O重定向的方式来恢复文件。

此文章来自固定链接:http://www.rakbuluo.com/p39

原文链接:,转发请注明来源!

发表评论

  • 79 Responses to “不小心执行了rm -f,除了跑路,如何恢复?”
    • epilepsy meds

      fantastic submit, very informative. I'm wondering why the other experts of this sector do not understand this. You should continue your writing. I am sure, you have a huge readers' base already! https://epilepsymedi.com epilepsy meds

      回复
    • osteoporosis medications

      I learned more new things on this weight loss issue. One issue is that good nutrition is highly vital when dieting. A huge reduction in fast foods, sugary foods, fried foods, sugary foods, red meat, and white flour products may be necessary. Holding wastes parasites, and toxins may prevent goals for losing fat. While certain drugs temporarily solve the problem, the nasty side effects are not worth it, and they never offer more than a temporary solution. It is a known fact that 95% of fad diets fail. Thanks for sharing your ideas on this blog. https://osteoporosismedi.com osteoporosis medications

      回复
    • medication for bronchitis

      I wanted to compose a comment in order to appreciate you for all of the awesome concepts you are giving at this site. My considerable internet investigation has at the end been compensated with beneficial content to exchange with my classmates and friends. I 'd admit that many of us readers actually are definitely blessed to be in a fabulous community with many awesome individuals with beneficial basics. I feel extremely blessed to have come across the site and look forward to many more amazing minutes reading here. Thank you again for a lot of things. https://bronchitismed.com medication for bronchitis

      回复
    • best Hypothyroidism meds

      Hello there, just became aware of your blog through Google, and found that it is really informative. I’m gonna watch out for brussels. I will appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers! https://hypothyroidismmed.com/ best Hypothyroidism meds

      回复
    • best epilepsy with least side effects

      great post, very informative. I wonder why the other experts of this sector do not realize this. You should continue your writing. I am sure, you have a huge readers' base already! https://epilepsymedi.com best epilepsy with least side effects

      回复
    • best bronchitis meds

      I actually wanted to construct a word to be able to thank you for those wonderful ways you are writing on this website. My time intensive internet search has now been rewarded with wonderful tips to write about with my visitors. I would tell you that we website visitors are very much lucky to live in a wonderful website with very many wonderful professionals with very helpful tricks. I feel very much privileged to have used your entire website page and look forward to tons of more thrilling times reading here. Thanks a lot once more for everything. https://bronchitismed.com most common antibiotic for bronchitis

      回复
    • what is prescribed for bronchitis

      I simply wanted to write a small word to be able to thank you for those superb tips you are showing on this website. My time consuming internet search has now been rewarded with sensible strategies to write about with my partners. I would state that that we website visitors are very lucky to live in a useful website with very many special professionals with very beneficial things. I feel very privileged to have used your entire website and look forward to tons of more pleasurable times reading here. Thanks a lot once more for everything. https://bronchitismed.com what is prescribed for bronchitis

      回复
    • bronchitis drugs for sale

      I just wanted to make a quick note so as to express gratitude to you for some of the nice recommendations you are posting here. My particularly long internet lookup has at the end of the day been paid with incredibly good information to share with my friends. I 'd express that most of us site visitors actually are truly endowed to dwell in a notable place with so many marvellous people with insightful points. I feel really grateful to have encountered your weblog and look forward to really more entertaining moments reading here. Thanks once again for a lot of things. https://bronchitismed.com buy bronchitis medications

      回复
    • best thyroid medication

      Hi there, just became alert to your blog through Google, and found that it's truly informative. I am going to watch out for brussels. I’ll be grateful if you continue this in future. Numerous people will be benefited from your writing. Cheers! https://hypothyroidismmed.com/ best thyroid medication

      回复
    • buy osteoporosis medications

      I figured out more a new challenge on this weight-loss issue. A single issue is a good nutrition is especially vital any time dieting. A massive reduction in junk food, sugary food, fried foods, sweet foods, beef, and white-colored flour products could possibly be necessary. Having wastes organisms, and harmful toxins may prevent ambitions for fat-loss. While selected drugs for the short term solve the challenge, the horrible side effects are certainly not worth it, and they also never present more than a non permanent solution. It is just a known idea that 95% of celebrity diets fail. Many thanks for sharing your thinking on this blog site. https://osteoporosismedi.com buy osteoporosis medications

      回复
    • buy epilepsy medications

      fantastic publish, very informative. I'm wondering why the opposite specialists of this sector don't understand this. You must proceed your writing. I'm confident, you've a great readers' base already! https://epilepsymedi.com buy epilepsy medications

      回复
    • heart ischemia drugs over the counter

      You got a very great website, Gladiola I observed it through google. https://heartischemiamed.com heart ischemia drugs over the counter

      回复
    • parkinson meds for sale

      Magnificent website. Plenty of helpful info here. I am sending it to several friends ans additionally sharing in delicious. And certainly, thanks to your sweat! https://parkinsonmedi.com parkinson meds for sale

      回复
    • best medicine for hyperactivity

      I am always searching online for articles that can help me. Thank you! https://hyperactivitymed.com best medicine for hyperactivity

      回复
    • best prescription drugs for epilepsy

      great post, very informative. I wonder why the other experts of this sector do not realize this. You should continue your writing. I am sure, you have a huge readers' base already! https://epilepsymedi.com best prescription drugs for epilepsy

      回复
    • buy heart ischemia drugs over the counter

      You got a very great website, Gladiola I discovered it through google. https://heartischemiamed.com buy heart ischemia drugs over the counter

      回复
    • parkinson drugs

      Fantastic web site. Lots of useful information here. I'm sending it to a few buddies ans also sharing in delicious. And obviously, thank you on your effort! https://parkinsonmedi.com parkinson drugs

      回复
    • buy hyperactivity medications

      I am continuously browsing online for ideas that can facilitate me. Thx! https://hyperactivitymed.com buy hyperactivity medications

      回复
    • best atherosclerosis drugs

      You got a very excellent website, Glad I detected it through google. https://atherosclerosismed.com best atherosclerosis drugs

      回复
    • Anxiety medication

      fantastic publish, very informative. I'm wondering why the opposite specialists of this sector don't understand this. You must proceed your writing. I'm confident, you've a great readers' base already! https://anxietymedi.com Anxiety medication

      回复
    • best medicine for myasthenia

      I am continually invstigating online for tips that can assist me. Thanks! https://myastheniamedi.com best medicine for myasthenia

      回复
    • Anxiety meds for sale

      excellent put up, very informative. I ponder why the opposite specialists of this sector don't notice this. You must proceed your writing. I'm confident, you've a great readers' base already! https://anxietymedi.com Anxiety meds for sale

      回复
    • buy cancer medications

      Fantastic web site. Lots of helpful info here. I am sending it to a few buddies ans additionally sharing in delicious. And naturally, thanks in your sweat! https://cancermedph.com buy cancer medications

      回复
    • Myasthenia gravis

      I am always searching online for articles that can help me. Thank you! https://myastheniamedi.com Myasthenia gravis

      回复
    • cancer medication for sale

      Magnificent website. Plenty of helpful info here. I am sending it to several friends ans additionally sharing in delicious. And certainly, thanks to your sweat! https://cancermedph.com cancer medication for sale

      回复
    • best prescription drugs for glaucoma

      You got a very excellent website, Gladiolus I detected it through google. https://glaucomamedi.com best prescription drugs for glaucoma

      回复
    • buy rheumatoid arthritis meds

      fantastic publish, very informative. I'm wondering why the opposite specialists of this sector don't understand this. You must proceed your writing. I'm confident, you've a great readers' base already! https://rheumatoidarthritismed.com buy rheumatoid arthritis meds

      回复
    • glaucoma threatment

      You got a very fantastic website, Gladiolus I observed it through google. https://glaucomamedi.com glaucoma threatment

      回复
    • buy aids meds online

      I am always searching online for articles that can help me. Thank you! https://hivmedi.com buy aids meds online

      回复
    • rheumatoid arthritis meds for sale

      magnificent publish, very informative. I ponder why the opposite specialists of this sector don't notice this. You must proceed your writing. I'm confident, you've a great readers' base already! https://rheumatoidarthritismed.com rheumatoid arthritis meds for sale

      回复
    • hiv threatment

      I am constantly looking online for posts that can aid me. Thx! https://hivmedi.com hiv threatment

      回复
    • antipsychotic medications list schizophrenia

      Excellent website. Plenty of helpful info here. I am sending it to several friends ans additionally sharing in delicious. And certainly, thanks to your sweat! https://schizophreniamedi.com antipsychotic medications list schizophrenia

      回复
    • multiple sclerosis news

      Today, with all the fast way of living that everyone is having, credit cards get this amazing demand throughout the market. Persons coming from every discipline are using credit card and people who not using the credit card have made arrangements to apply for one in particular. Thanks for giving your ideas in credit cards. https://multiplesclerosismed.com multiple sclerosis news

      回复
    • buy multiple sclerosis medications

      Today, considering the fast life-style that everyone leads, credit cards have a big demand throughout the economy. Persons throughout every area of life are using the credit card and people who aren't using the credit cards have made up their minds to apply for even one. Thanks for revealing your ideas about credit cards. https://multiplesclerosismed.com buy multiple sclerosis medications

      回复
    • how to treat dementia

      I am always searching online for articles that can help me. Thank you! https://dementiamedi.com how to treat dementia

      回复
    • best tuberculosis medication

      You got a very excellent website, Gladiolus I detected it through google. https://tuberculosismedi.com best tuberculosis medication

      回复
    • dementia drugs

      I am constantly looking online for posts that can facilitate me. Thx! https://dementiamedi.com dementia drugs

      回复
    • tuberculosis medications

      You got a very fantastic website, Gladiolus I detected it through google. https://tuberculosismedi.com tuberculosis medications

      回复
    • home remedies for stomach ulcers

      Helpful info. Fortunate me I found your site accidentally, and I am surprised why this twist of fate did not came about in advance! I bookmarked it. https://stomachulcersmedi.com home remedies for stomach ulcers

      回复
    • best stomach ulcers medications

      Helpful info. Fortunate me I found your site by chance, and I am surprised why this twist of fate did not came about in advance! I bookmarked it. https://stomachulcersmedi.com best stomach ulcers medications

      回复
    • hypertension meds for sale

      Today, taking into consideration the fast way of living that everyone is having, credit cards get this amazing demand throughout the market. Persons out of every discipline are using credit card and people who not using the credit card have made arrangements to apply for one in particular. Thanks for giving your ideas in credit cards. https://hypertensionmedi.com hypertension meds for sale

      回复
    • hypertension medications

      Today, considering the fast life-style that everyone leads, credit cards have a big demand throughout the economy. Persons throughout every area of life are using the credit card and people who aren't using the credit cards have made up their minds to apply for even one. Thanks for revealing your ideas about credit cards. https://hypertensionmedi.com hypertension medications

      回复
    • buy HCV threatment

      You got a very great website, Gladiola I observed it through google. https://hcvmedi.com buy HCV threatment

      回复
    • new drugs for alzheimer

      I am always searching online for articles that can help me. Thank you! https://alzheimermedi.com new drugs for alzheimer

      回复
    • HCV drugs

      You got a very fantastic website, Gladiolus I observed it through google. https://hcvmedi.com HCV drugs

      回复
    • Alzheimer drugs for sale

      I am continuously browsing online for ideas that can benefit me. Thx! https://alzheimermedi.com Alzheimer drugs for sale

      回复
    • types of inhalers for asthma

      You got a very excellent website, Glad I detected it through google. https://asthmamedi.com types of inhalers for asthma

      回复
    • best prescription allergy medication

      I am always searching online for articles that can help me. Thank you! https://allergymedi.com best prescription allergy medication

      回复
    • over the counter asthma inhaler

      You got a very excellent website, Gladiolus I detected it through google. https://asthmamedi.com over the counter asthma inhaler

      回复
    • over the counter Allergy drugs

      I am continually invstigating online for tips that can assist me. Thanks! https://allergymedi.com over the counter Allergy drugs

      回复
    • cheapest ulcerative colitis drug

      Helpful info. Fortunate me I found your site accidentally, and I am surprised why this twist of fate did not came about in advance! I bookmarked it. https://colitismedi.com cheapest ulcerative colitis drug

      回复
    • Colitis meds for sale

      Valuable information. Lucky me I discovered your website by accident, and I'm shocked why this accident didn't took place earlier! I bookmarked it. https://colitismedi.com Colitis meds for sale

      回复
    • best prescription drugs for varicose veins

      Today, with the fast lifestyle that everyone leads, credit cards have a huge demand in the economy. Persons from every field are using the credit card and people who are not using the card have lined up to apply for one. Thanks for sharing your ideas on credit cards. https://varicoseveinsmedi.com best prescription drugs for varicose veins

      回复
    • best prescription drugs for arthritis

      Great info and straight to the point. I am not sure if this is in fact the best place to ask but do you folks have any thoughts on where to get some professional writers? Thanks :) https://arthritismedi.com best prescription drugs for arthritis

      回复
    • buy Arthritis drugs over the counter

      Awsome article and right to the point. I don't know if this is truly the best place to ask but do you people have any ideea where to employ some professional writers? Thx :) https://arthritismedi.com buy Arthritis drugs over the counter

      回复
    • Hemorrhoids medication

      Today, with the fast lifestyle that everyone leads, credit cards have a huge demand in the economy. Persons from every field are using the credit card and people who are not using the card have lined up to apply for one. Thanks for sharing your ideas on credit cards. https://hemorrhoidsmedi.com Hemorrhoids medication

      回复
    • medication for hemorrhoids

      Today, with the fast way of life that everyone leads, credit cards have a huge demand in the economy. Persons from every area are using the credit card and people who are not using the card have arranged to apply for 1. Thanks for discussing your ideas on credit cards. https://hemorrhoidsmedi.com medication for hemorrhoids

      回复
    • liver pain drugs

      Very nice post and right to the point. I don't know if this is really the best place to ask but do you guys have any ideea where to hire some professional writers? Thanks in advance :) https://livermedi.com liver pain drugs

      回复
    • buy psoriasis meds

      Today, with all the fast way of living that everyone is having, credit cards get this amazing demand throughout the market. Persons coming from every discipline are using credit card and people who not using the credit card have made arrangements to apply for one in particular. Thanks for giving your ideas in credit cards. https://psoriasismedi.com buy psoriasis meds

      回复
    • prescription for psoriasis

      Today, with the fast lifestyle that everyone leads, credit cards have a huge demand in the economy. Persons from every field are using the credit card and people who are not using the card have lined up to apply for one. Thanks for sharing your ideas on credit cards. https://psoriasismedi.com prescription for psoriasis

      回复
    • buy psoriasis drugs over the counter

      Today, taking into consideration the fast way of living that everyone is having, credit cards get this amazing demand throughout the market. Persons out of every discipline are using credit card and people who not using the credit card have made arrangements to apply for one in particular. Thanks for giving your ideas in credit cards. https://psoriasismedi.com buy psoriasis drugs over the counter

      回复
    • best medicine for psoriasis

      Today, taking into consideration the fast chosen lifestyle that everyone is having, credit cards get this amazing demand throughout the market. Persons out of every arena are using credit card and people who not using the credit card have prepared to apply for just one. Thanks for spreading your ideas in credit cards. https://psoriasismedi.com best medicine for psoriasis

      回复
    • buy hair loss drugs

      Hello. splendid job. I did not imagine this. This is a splendid story. Thanks! https://hairlossbimedi.com buy hair loss drugs

      回复
    • hair loss drugs for women

      Hello. excellent job. I did not anticipate this. This is a excellent story. Thanks! https://hairlossbimedi.com hair loss drugs for women

      回复
    • liver pain medication

      Very nice post and right to the point. I don't know if this is really the best place to ask but do you guys have any ideea where to hire some professional writers? Thanks in advance :) https://livermedi.com liver pain medication

      回复
    • impotence medication

      Today, considering the fast life-style that everyone leads, credit cards have a big demand throughout the economy. Persons throughout every area of life are using the credit card and people who aren't using the credit cards have made up their minds to apply for even one. Thanks for revealing your ideas about credit cards. https://impotencemedi.com impotence medication

      回复
    • best impotence pills

      Today, taking into consideration the fast chosen lifestyle that everyone is having, credit cards get this amazing demand throughout the market. Persons out of every arena are using credit card and people who not using the credit card have prepared to apply for just one. Thanks for spreading your ideas in credit cards. https://impotencemedi.com best impotence pills

      回复
    • pożyczka

      Keep functioning ,terrific job! https://chwilowki-pozyczka.pl - pożyczka

      回复
    • pożyczka

      Keep functioning ,remarkable job! https://chwilowki-pozyczka.pl - pożyczka

      回复
    • chwilówka

      Keep working ,great job! https://chwilowki-pozyczka.pl - chwilówka

      回复
    • best liver medication

      Keep functioning ,impressive job! https://livermedi.com - best liver medication

      回复
    • medications used for kidney disease

      As a Newbie, I am always searching online for articles that can help me. Thank you

      回复
    • buy kidney drugs

      As a Newbie, I am constantly browsing online for articles that can aid me. Thank you

      回复
    • otc stomach drugs

      Thanks for your strategies. One thing really noticed is that often banks plus financial institutions know the dimensions and spending patterns of consumers plus understand that plenty of people max outside their cards around the trips. They correctly take advantage of this real fact and then start flooding a person's inbox plus snail-mail box by using hundreds of no interest APR credit cards offers shortly when the holiday season closes. Knowing that when you are like 98% in the American general public, you'll get at the one opportunity to consolidate financial debt and switch balances towards 0 rate credit cards. onnmlop https://pancreasmedi.com - otc stomach drugs

      回复
    • generic stomach medicine

      Thanks for your strategies. One thing really noticed is that often banks plus financial institutions know the dimensions and spending patterns of consumers plus understand that plenty of people max outside their cards around the trips. They correctly take advantage of this real fact and then start flooding a person's inbox plus snail-mail box by using hundreds of no interest APR credit cards offers shortly when the holiday season closes. Knowing that when you are like 98% in the American general public, you'll get at the one opportunity to consolidate financial debt and switch balances towards 0 rate credit cards. onnmlop https://stomachmedi.com - generic stomach medicine

      回复
    • what to take for thyroid pain

      Thanks for your concepts. One thing we've noticed is banks along with financial institutions are aware of the spending practices of consumers while also understand that most of the people max out there their real credit cards around the getaways. They properly take advantage of this specific fact and commence flooding your current inbox along with snail-mail box using hundreds of no-interest APR card offers just after the holiday season comes to an end. Knowing that should you be like 98% of American community, you'll rush at the possiblity to consolidate card debt and shift balances for 0 apr interest rates credit cards. iiihhjm https://thyroidmedi.com - what to take for thyroid pain

      回复
    • canadian pharmacies mail order

      <a href="http://canadiannextpharmacy.com/">best mexican online pharmacies</a>
      http://canadiannextpharmacy.com/
      <a href=http://canadiannextpharmacy.com/>online pharmacy reviews</a>

      回复
    • Stephenpeaky

      viagra walgreens <a href=" http://sild100fast.com/# ">buy cheap viagra</a> viagra online canadian pharmacy

      回复
    • pharmacy in canada

      <a href="http://canadianpharmacynethd.com/">pharmacy drugstore online</a>
      http://canadianpharmacynethd.com/
      <a href=http://canadianpharmacynethd.com/>certified canadian online pharmacies</a>

      回复