linux防误删操作(使用safe-rm;使用mv命令删除文件)
本文于2021年1月16日由AlvinCR更新
文章导引
1.基于文本的Linux为什么没有回收站?
个人观点:
1.linux是指令行操作系统,不同于win的图形化界面,linux无法方便的快速恢复文件,例如linux下使用mv可以达到win下回收站相同的效果,但是却并没有人使用mv+文件名+路径的方法,实际上只需要在根目录下建立一个名为trash的文件夹,完全可以实现回收站的功能,具体是因为什么原因而不去使用mv,我个人认为就是因为不方便,并且使用linux的用户大部分并非计算机小白,一般情况下知道自己在做什么。
2.linux删除文件的时候,如果使用rm -r会有一个提示是否删除,类似于win10的简易回收站,只不过不进行储存,而是需要直接确认文件是否删除罢了。(现在写代码的时候很多资料都是教导使用rm -rf)
他人观点:
1.
树形的文件系统和回收站是不搭的。难道十八级目录都删了,从回收站恢复时,再把整个目录结构再恢复吗?日常生活中垃圾桶翻出来的东西多半是没法用了的。正是因为计算机里删除一个文件这个操作本身并不会改变文件内容,所以扔进垃圾桶里的还能拿出来继续用。现在的问题在于事实上我们只有一种形式的文件系统,也就是树形的。这对于存储个人文件来说,既无必要,也不方便。我们更应该把树形的文件系统去掉。只保留BeFS里索引的功能。删除文件只是给文件打个标记。等磁盘空间占满了再来提示你删除文件。https://www.zhihu.com/question/32294243/answer/135858069
2.
原文:
I think you may be sadly uninformed about what is and OS and what is a GUI.
When using the CLI in either Windows or Linux the delete/rm command does in fact immediately delete a file. And there are utilities that can attempt to recover such files if used immediatel after the mistake happens.
Every GUI I have seen in Linux does have a trash can. Linux GUIs I have seen also come with backup software and if they don’t a script file using rsync isn’t hard to write/find in order to efficiently backup the drives.
You might read this rather dated article about how to use the trashcan even from the CLI.
How to manage Trash can or Recycle bin in Linux Desktop graphic environment
翻译:
在Windows或Linux中使用CLI时,delete / rm命令实际上确实会立即删除文件。并且,如果在错误发生后立即使用了实用程序,它们可以尝试恢复此类文件。
我在Linux中看到的每个GUI都有一个垃圾桶。我见过的Linux GUI也附带了备份软件,如果它们不使用rsync编写脚本文件,则不难编写/查找以便有效地备份驱动器。
3.
下面这个观点和我的类似
原文:
linux was generally for competent users…you can delete a file and ask for cofirmation rm -i filename.
also a competent user has backups…so even if most files got removed it would be ok
but if a library was removed or something like that, then you are in trouble. as you dont back these things up..and it may make your system unworkable …that said you can easily with a little bit of know how chroot into your system or you can use a live dvd and reinstall the library.
bottom line is once you use linux for a while you will delete required files…but chances are …you will only do this once.
linux is made to be used from command line and in windows if you delete something from command line i dont even think there is a dustbin.
翻译:
linux通常适用于有能力的用户……您可以删除文件并要求确认rm -i filename。
一个有能力的用户也有备份…因此即使删除了大多数文件也没关系
但是,如果删除了某个库或类似的库,那么您就会遇到麻烦。因为您不备份这些内容,这可能会使您的系统无法正常工作……这表示您可以轻松地将chroot导入系统,也可以使用实时DVD并重新安装该库。
最重要的是,一旦您使用linux一段时间,您将删除所需的文件…但是很可能……您只会执行一次。
linux是从命令行使用的,在Windows中,如果您从命令行删除某些内容,我甚至都不认为有垃圾箱。
2.使用safe-rm包
2.1 安装
不建议熟悉linux的用户使用该方法,本文只是提供思路
Safe-rm是一种安全工具,旨在通过使用包装程序替换/ bin / rm来防止重要文件的意外删除,该包装程序将对给定的参数与永不删除的可配置文件和目录黑名单进行检查。
wget https://launchpad.net/safe-rm/trunk/0.12/+download/safe-rm-0.12.tar.gz
tar -xzvf safe-rm-0.12.tar.gz
cd safe-rm-0.12
vi /etc/profile 可以在最后一行添加PATH路径:PATH=/usr/local/bin:$PATH
source /etc/profile
vi /etc/safe-rm.conf
然后输入需要重点保护的文件夹的目录即可
注意: 这样写可以避免 test 目录和 test 目录下的普通文件被删除,但无法避免 test 目录下链接文件被删除。所以像
/lib
或/lib64
这种目录,下面会有很多对库文件的链接文件,使用safe-rm
并不能保护文件。(参考:https://linuxgeeks.github.io/2015/11/25/172103-%E4%BD%BF%E7%94%A8safe-rm%E9%81%BF%E5%85%8Drm%E5%91%BD%E4%BB%A4%E8%AF%AF%E5%88%A0%E6%96%87%E4%BB%B6/,备注:该参考网站的方法在我的机器上实现起来有问题,不建议看原文)
2.2效果:
3.禁用rm命令,改用mv命令
不建议熟悉linux的用户使用该方法,本文只是提供思路
2021.1.9补充:
要删除文件,可以设置一个文件夹,将需要删除的文件到移动指定目录/delete/,启动一个定时任务,让其在特定的时间内清除/delete/下文件。
4.恢复工具extundelete
4.1 恢复原理:
在Linux下可以通过“ls –id”命令来查看某个文件或者目录的inode值,例如查看根目录的inode值,可以输入:
由此可知,根目录的inode值为2。
在利用extundelete恢复文件时并不依赖特定文件格式,首先extundelete会通过文件系统的inode信息(根目录的inode一般为2)来获得当前文件系统下所有文件的信息,包括存在的和已经删除的文件,这些信息包括文件名和inode。然后利用inode信息结合日志去查询该inode所在的block位置,包括直接块,间接块等信息。最后利用dd命令将这些信息备份出来,从而恢复数据文件。
参考:https://blog.csdn.net/coco3600/article/details/100232811
4.2安装使用
常见的开源恢复工具有:debugfs、R-Linux、ext3grep、extundelete,下面是extundelete操作方法
1、安装依赖包
yum -y install e2fsprogs-devel gcc2、解压工具包
tar jxf extundelete-0.2.4.tar.bz23、指定安装目录、编译、编译安装
./configure ; make ; make install
使用
常用参数:
--after dtime 时间参数,表示在某段时间之后被删除的文件或目录 --before dtime 时间参数,表示在某段时间之前被删除的文件或目录 --inode ino 显示节点 ino 的信息 --block blk 显示数据块 blk 的信息 --restore-inode ino 表示恢复节点 ino 的文件,用来恢复单个文件 --restore-file path 表示恢复指定路径下的文件,用来恢复目录下所有文件 --restore-all 表示恢复所有被删除的目录跟文件开启恢复流程:
1、查找被删除文件所在目录 id
ls -id /xxx/xxx/注:输出最左侧为ID号。
2、查看被删除的上层目录 inode
# extundelete 所在分区名称 --inode ID号 extundelete /dev/sdb1 --inode 1306193、恢复数据、恢复指定目录下所有删除的数据
# extundelete 数据所在分区名称 --restore-directory 恢复数据的目录 extundelete /dev/sdb1 --restore-directory /xxx/xxx/xxx/4、完成恢复后续工作
# 恢复数据后,会把恢复数据送到当前路径的RECOVERED_FILES/内,再把恢复的数据拿回原处 cp RECOVERED_FILES/xxx/xxx/* /xxx/xxx/xxx/
方法来源:https://www.cnblogs.com/xiangsikai/p/10779457.htmlhttps://www.cnblogs.com/xiangsikai/p/10779457.html
45条评论
Royal CBD
Thank you a lot for sharing this with all of us you actually recognise what you are speaking approximately!
Bookmarked. Kindly additionally seek advice from my website =).
We will have a hyperlink alternate agreement between us
Look at my homepage Royal CBD
AlvinCR
Thanks for your kindness, but I would better share the website which relates to computer science.
I am looking for sex, but do you want? Come in here https://katrrina.page.link/ATzv
I am looking for sex, but do you want? Come in here
https://asya.page.link/emKW
AlvinCR
Sorry, I do not get your point.
Kam
Hi there all, here every one is sharing these knowledge, thus
it’s pleasant to read this webpage, and I used to pay a quick visit this blog all the time.
Also visit my web site; Kam
AlvinCR
Thank you for the affirmation. ^ – ^
hi, u can fund more my nude photos here - add me now https://hellena.page.link/e2Am
Hi! If you want to pull me on your stick, then message me where we can meet. Message there
https://katrrina.page.link/H7ss
https://nancymarkle.com
I know this website offers quality based posts and extra stuff,
is there any other site which gives these kinds of data in quality?
is there a generic viagra
viagra from india is there a generic viagra where to buy viagra
online
Burton
I do agree with all of the concepts you’ve
introduced on your post. They’re very convincing and will
certainly work. Nonetheless, the posts are too brief for newbies.
May just you please prolong them a little from subsequent time?
Thank you for the post.
my homepage … Burton
AlvinCR
Thanks for your recommendation. I will prolong them.
cialis pill
Cialis daily https://mycialedst.com/ generic viagra
generic cialis online
Cialis generic phrcialiled.com tadalafil cheap
online pharmacy
Cialis without a doctor prescription https://21cialismen.com cialis buy
cialis buy
Viagra https://cialijomen.com/ tadalafil pills
coin master free spin
Thanks for your marvelous posting! I quite enjoyed reading it, you
happen to be a great author. I will ensure that I bookmark your blog and will often come back very soon. I
want to encourage you to continue your great work, have a
nice day!
get a loan online
Instant loan online get a loan online online loans for bad credit
robux generator
You can definitely see your expertise in the article
you write. The world hopes for more passionate writers such as you who aren’t afraid to say
how they believe. All the time go after your heart. https://www.physiology.utoronto.ca/sites/default/files/webform/roblox-robux-hack.pdf
bad credit payday loans
Instant payday loans bad credit payday loans instant payday loans online
robux generator
You can definitely see your expertise in the article
you write. The world hopes for more passionate writers such as you who aren’t afraid to say
how they believe. All the time go after your heart. https://hillel.princeton.edu/sites/default/files/webform/twist-amazing-free-roblox-robux-generator-works-students-loving.pdf
unsecured personal loans guaranteed approval
Low interest rate personal loans unsecured personal loans guaranteed approval low interest rate personal loans
small personal loans online
Poor credit personal loans personal4usloans.com personal installment
loans
Donaldovews
pharmacy drugs canadian pharmacy canadian pharmacies online
viagra song
Over the counter viagra cvs https://viashoprx.com viagra
generic
negarapoker bandarq terpercaya
linux防误删操作(使用safe-rm;使用mv命令删除文件)(更新中) | AlvinCR | 解语·花言博客 negarapoker dominoqq
https://bibliotecas.cartagena.es/gestion/comun/estadisticas/banners.asp?b=223&i=1&z=1&url=http%3A%2F%2Fforo.unionfansub.com%2Fmember.php%3Faction%3Dprofile%26uid%3D145678 | negarapoker dominoqq link aman
cialis coupon
Tadalafil buy https://cialmenshoprx.com cialis buy
cialis buy
Cialis pill http://acialaarx.com cialis 20mg
generic viagra online
Sildenafil vs viagra http://hitrxmenvia.com/ viagra
for women
cheap viagra
Where to buy viagra cheap viagra over the counter viagra cvs
canada drugs online pharmacy
co pharmacy https://canadiantrypharmacy.com – best non prescription online pharmacies
buy cialis online
You have made your position pretty effectively..
http://canadian1pharmacy.com viagra for sale
buy viagra
Sudden sweating or flu-like symptoms, including nausea, clamminess or cold sweats.
http://viarxhd.com/ Sudden sweating or flu-like symptoms, including nausea, clamminess or cold sweats.
how does viagra work
For example, the treatment for ringworm for pregnant and the breastfeeding mothers might differ depending on the situation than the
people who are in different medications, like hypertension, cancer, etc.
how does viagra work For example,
the treatment for ringworm for pregnant and the breastfeeding mothers might differ depending on the situation than the people who are in different medications, like
hypertension, cancer, etc.
canadian drugstore online
canadian pharmacy rx http://viaciabox.com – international drug mart canadian pharmacy online store canadian online pharmacy
kamagra 100mg oral jelly
You’ve made your stand quite effectively.!, kamagra gel alcohol https://kamagrahome.com kamagra viagra
viagra natural
When they expressed their concerns, doctors only shrugged their shoulders and told them to
stop using Google for information. viagra natural When they expressed their concerns, doctors only shrugged their shoulders and told them to
stop using Google for information.
generic viagra online for sale
“Drug Episodes vs. Drug Mentions buygenericviarga.com “Drug Episodes vs. Drug Mentions
generic for viagra
Autoimmune Connection: Essential Information for Women on Diagnosis, Treatment,
and Getting On with Your Life by Rita Baron-Faust and Jill Buyon The Multiple Sclerosis Diet Book: A Low-Fat
Diet for the Treatment of M. http://buyhdpillvia.com/ Autoimmune Connection: Essential Information for Women on Diagnosis, Treatment, and Getting On with
Your Life by Rita Baron-Faust and Jill Buyon The Multiple Sclerosis Diet Book:
A Low-Fat Diet for the Treatment of M.
buy generic 100mg viagra online
Our guest is Dr. buy generic 100mg viagra online Our guest is Dr.
buy viagra online cheap
Referred shoulder pain occurs when pain is experienced in an area away from the actual injury or problem.
ltdviagragogo.com Referred shoulder pain occurs when pain is experienced in an area away from the
actual injury or problem.
kamagra 100mg
can tylenol raise blood pressure kamagra poland https://www.goldkamagra.com – kamagra jelly
how long does viagra last
Nurse: he’s breathingMe: It’s disturbing that he’s half out of his chair.
how long does viagra last Nurse: he’s breathingMe:
It’s disturbing that he’s half out of his chair.
kamagra 100
You explained that exceptionally well., buy cheap kamagra online uk http://www.kamagrapolo.com kamagra
payday loans online fast deposit
http://www.loansonline1.com loans
viagra without a doctor prescription
https://www.withoutvisit.com viagra without a doctor prescription