新聞中心
Linux操作系統(tǒng)被眾多程序員和服務(wù)器管理員視為最強(qiáng)的開(kāi)源系統(tǒng)。但是,任何系統(tǒng)都不是完美無(wú)缺的。在Linux系統(tǒng)上,誤刪數(shù)據(jù)是一個(gè)普遍存在的問(wèn)題。雖然有很多方法可以防止誤刪,但是如果數(shù)據(jù)已經(jīng)被刪除,該怎么辦?

專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)沂南免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
在Linux系統(tǒng)中,ifind是一個(gè)非常有用的命令,可以幫助你找回誤刪除的文件。ifind的作用是搜索已刪除的文件,找到相關(guān)的inode,并將其恢復(fù)為可用狀態(tài)。
ifind命令原理
首先需要明確,當(dāng)在Linux系統(tǒng)中刪除一個(gè)文件時(shí),只是將inode表中的相關(guān)信息標(biāo)記為“已刪除”,而實(shí)際數(shù)據(jù)仍然駐留在磁盤(pán)上。這就是ifind命令的原理所在。ifind命令將使用類似于grep的方式搜索已經(jīng)刪除的inode,并將其恢復(fù)為可用狀態(tài)。因此,如果在刪除文件后馬上執(zhí)行ifind命令,則可能會(huì)找到丟失的文件并恢復(fù)它。
ifind的使用
在Linux系統(tǒng)中,ifind命令的使用非常簡(jiǎn)單。在開(kāi)始之前,請(qǐng)確定您有sudo權(quán)限。
要使用ifind命令來(lái)尋找誤刪除的文件,請(qǐng)按照以下步驟操作:
1. 在終端中輸入命令:sudo ifind。這將顯示可以恢復(fù)的 inode 的整個(gè)列表。
2. 找到您要恢復(fù)的文件的 inode,并將其寫(xiě)入文件。
3. 使用istat查找inode的詳細(xì)信息。
4. 如果您已經(jīng)找到了需要的文件,請(qǐng)使用命令sudo icat 。這將輸出文本到屏幕上。將其保存到文件中,然后將文件的擴(kuò)展名更改為正確的擴(kuò)展名。
需要注意的是,如果您發(fā)現(xiàn)使用ifind命令后找不到您要找的文件,則可能是由于它已經(jīng)完全被覆蓋或者過(guò)早地被刪除。在這種情況下,恢復(fù)文件變得非常困難。
如何避免誤刪數(shù)據(jù)?
雖然ifind是恢復(fù)誤刪數(shù)據(jù)的極好方法,但是仍然建議您采取措施避免數(shù)據(jù)丟失。以下是一些常用的方法:
1. 創(chuàng)建備份:在Linux系統(tǒng)上,備份數(shù)據(jù)是非常重要的。將所有關(guān)鍵數(shù)據(jù)備份到本地或遠(yuǎn)程服務(wù)器中以確??梢曰謴?fù)所有丟失的數(shù)據(jù)。
2. 慎用rm:在刪除文件之前,更好仔細(xì)檢查文件名和文件路徑,以確保不會(huì)刪除不必要的文件。建議使用rm -i命令,該命令會(huì)在刪除之前提示確認(rèn)。
3. 限制訪問(wèn)權(quán)限:通過(guò)設(shè)置適當(dāng)?shù)奈募湍夸洐?quán)限來(lái)限制文件的訪問(wèn)。這可以幫助防止不必要的文件訪問(wèn)和誤刪除數(shù)據(jù)。
相關(guān)問(wèn)題拓展閱讀:
- 如何解決SELinux問(wèn)題
- 如何解決 artdot indi.mail system
如何解決SELinux問(wèn)題
首先需要確認(rèn)SELinux處于激活狀態(tài),可以使用getenforce命令:
兄凳 shell> getenforce
Enforcing
或者使用sestatus命令:
shell> sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file:enforcing
Policy version: 24
Policy from config file:targeted
注:關(guān)于SELinux的基礎(chǔ)知識(shí)介紹請(qǐng)參考鳥(niǎo)哥的Linux私房菜中相關(guān)的介紹。
我們還需要確認(rèn)系統(tǒng)已經(jīng)安裝并啟動(dòng)了Apache,沒(méi)有的話就YUM裝一個(gè),這很簡(jiǎn)單,就不多說(shuō)了,接著在root目錄創(chuàng)建一個(gè)測(cè)試文件test.html,如下:
shell> cat /root/test.html
hello, world.
然后把這個(gè)測(cè)試文件拷貝到Apache的DocumentRoot目錄,我的Apache是通過(guò)YUM安裝的話,缺省是/var/www/html目錄,如下:
shell> cp /root/test.html /var/www/html
接著瀏覽一下,如果沒(méi)出什么幺蛾子,應(yīng)該一切都在意料之中,如下:
shell> curl
hello, world.
看到這,你可能覺(jué)得我廢話連篇,別著急,下面就是見(jiàn)證奇跡的時(shí)候了:
同樣還是那個(gè)測(cè)試文件test.html,不過(guò)這次不再是拷貝,而是移動(dòng),如下:
shell> mv /root/test.html /var/www/html
接著瀏覽一下,怎么樣,結(jié)果很出人意料吧,竟然提示權(quán)限錯(cuò)誤,如下:
shell> curl
403 Forbidden
Forbidden
You don’t have permission to access /test.html
on this server.
當(dāng)然,我們現(xiàn)在知道這個(gè)問(wèn)題是由于SELinux引起的,但還不知其所以然,實(shí)際上問(wèn)題的原因此時(shí)已經(jīng)被螞鄭audit進(jìn)程記錄到了相應(yīng)的日志里,可以這羨物旅樣查看:
shell> audit2why yum install setroubleshoot
它本身是一個(gè)GUI套件,不過(guò)其中包含的一個(gè)sealert命令對(duì)我們命令行用戶很有用:
shell> sealert -a /var/log/audit/audit.log
Summary:
SELinux is preventing /usr/in/httpd “getattr” access to
/var/www/html/test.html.
Detailed Description:
SELinux denied access requested by httpd. /var/www/html/test.html may be a
mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,
but its current type is admin_home_t. Changing this file back to the default
type, may fix your problem.
File contexts can be assigned to a file in the following ways.
* Files created in a directory receive the file context of the parent
directory by default.
* The SELinux policy might override the default label inherited from the
parent directory by specifying a process running in context A which creates
a file in a directory labeled B will instead create the file with label C.
An example of this would be the dhcp client running with the dhclient_t type
and creating a file in the directory /etc. This file would normally receive
the etc_t type due to parental inheritance but instead the file is labeled
with the net_conf_t type because the SELinux policy specifies this.
* Users can change the file context on a file using tools such as chcon, or
restorecon.
This file could have been mislabeled either by user error, or if an normally
confined application was run under the wrong domain.
However, this might also indicate a bug in SELinux because the file should not
have been labeled with this type.
If you believe this is a bug, please file a bug report against this package.
Allowing Access:
You can restore the default system context to this file by executing the
restorecon command. restorecon ‘/var/www/html/test.html’, if this file is a
directory, you can recursively restore using restorecon -R
‘/var/www/html/test.html’.
Fix Command:
/in/restorecon ‘/var/www/html/test.html’
這次應(yīng)該看懂了吧!原因是說(shuō)Apache下文件上下文類型應(yīng)該是httpd_sys_content_t,但是現(xiàn)在是admin_home_t,所以權(quán)限錯(cuò)誤,并且在結(jié)尾處給出了修復(fù)命令。
可httpd_sys_content_t,admin_home_t都怎么看啊?很簡(jiǎn)單,借助ls命令的-Z參數(shù)即可:
shell> ls -Z /path
回到問(wèn)題的開(kāi)始,拷貝之所以沒(méi)出現(xiàn)問(wèn)題,是因?yàn)閏p自動(dòng)修改上下文屬性,而移動(dòng)之所以出現(xiàn)問(wèn)題是因?yàn)閙v保留原文件的上下文屬性。
注:關(guān)于SELinux和Apache的詳細(xì)介紹,可以參考『man httpd_selinux』。
知道了如何解決SELinux問(wèn)題,以后如果遇到類似的情況不要急著武斷的關(guān)閉SELinux。
有碰到即使是permissive也不行的,最后是改成disabled后重啟機(jī)器才可以。
上面有個(gè)小錯(cuò),應(yīng)該是echo “0” > /selinux/enforce (少了>)selinux如果有開(kāi)很容易雀塵造成ifind問(wèn)題,參看下面系統(tǒng)日志Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/ifind “execstack”梁歲枯 access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /橡洞bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-bc0fd2d308
別一種查看SElinux方法:# sestatusSELinux status: disabled
如何解決 artdot indi.mail system
上面陪神有個(gè)小錯(cuò),應(yīng)該是echo “0” > /selinux/enforce (少了>)selinux如果有開(kāi)很容易造成ifind問(wèn)題,參看下面系統(tǒng)日志兆亂鄭Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/族頌ifind “execstack” access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-bc0fd2d308
設(shè)置-兼容性視圖設(shè)置-添加此網(wǎng)站(將需打開(kāi)的郵箱網(wǎng)址增加進(jìn)去)ok
關(guān)于linux ifind的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
成都網(wǎng)站推廣找創(chuàng)新互聯(lián),老牌網(wǎng)站營(yíng)銷(xiāo)公司
成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)(www.cdcxhl.com)專注高端網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì)制作,網(wǎng)站維護(hù),網(wǎng)絡(luò)營(yíng)銷(xiāo),SEO優(yōu)化推廣,快速提升企業(yè)網(wǎng)站排名等一站式服務(wù)。IDC基礎(chǔ)服務(wù):云服務(wù)器、虛擬主機(jī)、網(wǎng)站系統(tǒng)開(kāi)發(fā)經(jīng)驗(yàn)、服務(wù)器租用、服務(wù)器托管提供四川、成都、綿陽(yáng)、雅安、重慶、貴州、昆明、鄭州、湖北十堰機(jī)房互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)。
新聞名稱:Linux ifind命令:找回誤刪文件! (linux ifind)
本文URL:http://www.dlmjj.cn/article/djeggid.html


咨詢
建站咨詢
