本人從事IT行業(yè)已有十多年端铛,有著豐富的實(shí)戰(zhàn)經(jīng)驗(yàn)蚤告,總結(jié)了大量的學(xué)習(xí)方法,更是積累了很多的學(xué)習(xí)資料矗漾,很高興能在這里跟大家交流學(xué)習(xí)锈候,希望能在這里跟大家共同進(jìn)步和成長!
全套學(xué)習(xí)資料移步至公眾號【學(xué)神來啦】
?本節(jié)所講內(nèi)容:
??4.1 ?vim的使用
??4.2 ?實(shí)戰(zhàn):恢復(fù)ext4文件系統(tǒng)下誤刪除的文件
??4.3 ?實(shí)戰(zhàn):使用xfs_undelete恢復(fù)誤刪除文件
??4.4??實(shí)戰(zhàn):使用xmanager等遠(yuǎn)程連接工具管理Linux
4.1 ?vim主要模式介紹
vim命令模式
問:vi和vim是同一個軟件包安裝的嗎?
答:NO敞贡,vim是vi的增加版泵琳,最明顯的區(qū)別就是vim可以語法加亮,它完全兼容vi
查看一個命令,是哪個軟件包获列,安裝的:
[root@xuegod63 ~]# rpm -qf /usr/bin/vim
[root@xuegod63 ~]# which vim
[root@xuegod63?~]# rpm -qf `which vim` ??#`反引號谷市,esc按鍵下的鍵,反引號中可執(zhí)行命令
[root@xuegod63?~]# rpm -qf $(which vi) ??#$(可執(zhí)行命令)
$() 與`` 都可以進(jìn)行命令替換击孩,命令替換與變量替換差不多迫悠,都是用來重組命令行的,先完成引號里的命令行巩梢,然后將其結(jié)果替換出來创泄,再重組成新的命令行
4.1.1 ?vim編輯器的四種操作模式
1.Vim常用4種模式.
正常模式(Normal mode,俗稱命令模式) ?括蝠,命令行模式(Command-line?mode)
插入模式(Insert mode?验烧,俗稱編輯模式), 可視模式(Visual mode又跛,俗稱可視塊模式)
[root@xuegod63 ~]# cp /etc/passwd a.txt
[root@xuegod63 ~]# vim a.txt
首次進(jìn)入文件? ?????????----正常模式(Normal mode,俗稱命令模式)
按下I鍵若治,出現(xiàn) “Insert”?? ----插入模式(Insert mode?慨蓝,俗稱編輯模式)
按Esc鍵,再輸入冒號: ?????----命令行模式(Command-line?mode)
例1從編輯模式到命令行模式怎樣切換?
編輯模式->esc->命令模式->:?->命令行模式
注意在命令模式下端幼,輸入命令無效時礼烈,檢查下輸入法是不是中文輸入法,切換為英文輸入法
例2字符操作(怎樣進(jìn)入編輯模式?)
進(jìn)入編輯模式a i oA I O
說明:
i 當(dāng)前字符之前插入 (光標(biāo)前)
I 行首插入 ?(行首)
a 當(dāng)前字符之后插入 (光標(biāo)后)
A 行尾插入(行尾)
o下一行插入 (另起一行)
O上一行插入(上一行插入)
x 向后刪除一個字符等同于delete
X 向前刪除一個字符 ????
u 撤銷一步 每按一次就撤銷一次
ctrl+r 恢復(fù)婆跑,每按一次就恢復(fù)一次
r 替換
4.1.2 ?在正常模式下做的操作:
1此熬、光標(biāo)定位
hjkl ?左下上右
0 和 home鍵表示切換到行首, $和end鍵表示切換到行尾
gg 快速定位到文檔的首行 , ?G定位到未行
3gg 或者 3G ?快速定位到第3行
/string(字符串) ??-----找到或定位你要找的單詞或內(nèi)容然后敲回車滑进,如果相符內(nèi)容比較多犀忱,我們可以通過N、n來進(jìn)行向上向下查找扶关,并且vim會對查找到的內(nèi)容進(jìn)行高亮顯示阴汇,取消高亮用 :noh
/^d ?----尖括號^意思表示以什么開頭 ,查找以字母d開頭的內(nèi)容
/bash$ ??-----$意思表示以什么結(jié)尾节槐,查找以字母bash結(jié)尾的內(nèi)容
vim + /etc/passwd??打開文件后搀庶,光標(biāo)會自動位于文件的最后一行。 了解一下這個技巧铜异。
vim +23 /etc/passwd??打開文件后哥倔,光標(biāo)會自動位于文件的第23行,方便后期排錯揍庄。如:服務(wù)器啟動報(bào)錯咆蒿,第23,有語法錯誤。使用vim +23 /etc/passwd可以快速定位到23行蜡秽。
分享心得:我更喜歡vim打開文件府阀,然后按G,跳到最后芽突。 因這個vim + a.txt ?技巧不常用试浙,過一段時間肯定會忘。Linux中有太多的小技巧寞蚌,大家應(yīng)該記那些常用的田巴。
2、在正常模式對文本進(jìn)行編輯
刪除挟秤、復(fù)制壹哺、粘貼、撤銷
yy復(fù)制整行 ?
復(fù)制N行: Nyy ?艘刚,比如: 2yy 管宵,表示復(fù)制2行
dd(刪除,以行為單位攀甚,刪除當(dāng)前光標(biāo)所在行)
刪除N行: Ndd ?箩朴,比如: 2dd ,表示刪除2行
p : P粘貼
剪切: dd
x 刪除光標(biāo)所在位置的字符
D 從光標(biāo)處刪除到行尾
u ?撤銷操作
ctrl+r ?還原撤銷過的操作秋度,將做過的撤銷操作再還原回去炸庞,也就是說撤銷前是什么樣,再還原成什么樣
r 替換荚斯,或者說用來修改一個字符
總結(jié):vim如何進(jìn)入其它模式
a A ?o O ?i I 都是可以進(jìn)行插入埠居,編輯模式
: 進(jìn)入命令行模式
ctrl+v 進(jìn)入可視塊模式
R 擦除、改寫事期,進(jìn)入替換模式
你進(jìn)入以上模式后滥壕,想要退出 ,按esc
4.1.3 ?Visual mode可視塊模式
編程或修改服務(wù)器配置文件的時候兽泣,需要進(jìn)行多行注釋捏浊,會使用Visual模式。
1撞叨、進(jìn)入Visual模式的批量刪除金踪,方法如下:
刪除:再按ctrl+v 進(jìn)入可視塊模式;向下或向上移動光標(biāo)?牵敷;選中部分內(nèi)容,然后按d, 就會刪除注釋符號胡岔。
例:將sshd_config?文件中17行到20行前面的#號刪除
[root@xuegod63 ~]# vim /etc/ssh/sshd_config
改:
?為:
2、進(jìn)入Visual模式的批量修改枷餐,方法如下:
1)靶瘸、ctrl+v 進(jìn)入列編輯模式
2)、向下或向上移動光標(biāo),把需要注釋怨咪、編輯的行的開頭選中起來
4)屋剑、然后按大寫的I
5)、再插入注釋符或者你需要插入的符號,比如"#"
6)诗眨、再按Esc,就會全部注釋或添加了
例:在sshd_config?文件中17行到20行前面加一個#號
[root@xuegod63 ~]# vim /etc/ssh/sshd_config
改:
為:
4.1.4 ?命令行模式Command-line操作技巧
1唉匾、命令行模式Command-line操作技巧
:w 保存 save
:w!?強(qiáng)制保存
:q 沒有進(jìn)行任何修改,退出 quit
:q! 修改了匠楚,不保存巍膘,強(qiáng)制退出
:wq 保存并退出
:wq!?強(qiáng)制保存并退出
:x 保存退出
:e! 復(fù)原,恢復(fù)到文件打開后芋簿,沒有進(jìn)行修改時的狀態(tài)峡懈。 修改了很多,不想保存与斤,想復(fù)原肪康,按:e!
在正常模式下,按下大寫的ZZ撩穿,也可以保存并退出
例:?wq!?強(qiáng)制保存并退出
[root@xuegod63 ~]# ll /etc/shadow
----------. 1 root root 1179 9月 ?19 12:57 /etc/shadow
[root@xuegod63 ~]# vim /etc/shadow
例1:調(diào)用外部文件或命令
語法:在命令行模式下輸入: !+命令
例:在vim編輯文檔寫要寫入MAC地址磷支。
[root@xuegod63 ~]# cp /etc/passwd a.txt
[root@xuegod63 ~]# vim a.txt
:!ifconfig ????#在vim中調(diào)用ifconfig命令
讀取其他文件。(把其他文件中的內(nèi)容追加到當(dāng)前文檔中)
:r /etc/hosts
2冗锁、文本替換
格式 :?范圍(其中%所有內(nèi)容) ??s分隔符 舊的內(nèi)容 分隔符 新的內(nèi)容 ?(分隔符可以自定義)
默認(rèn)是每一行的第一個符合要求的詞 ??(/g全部)
[root@xuegod63 ~]# vim a.txt
:1,3 s/bin/xuegod ????#替換第1到3行中出現(xiàn)的第一個bin進(jìn)行替換為xuegod
:1,3 s/bin/xuegod/g ??#替換第1到3行中查找到所有的bin進(jìn)行替換為xuegod
:3 s/xue/aaaaa/g ???????#只把第3行中所有xue替換為aaaaa了
修改a.txt ,先在文件中隨意插入幾個do 和DO 字符
:% s/do/xuegod/g?????#將文本中所有的do替換成xuegod
:% s/do/xuegod/gi ????#將文本中所有的do替換成xuegod, 并且忽略do的大小寫
:% s@xuegod@do@g #將文本中所有的xuegod替換成do嗤栓,替換時冻河,也可以使用@做分隔符
4.1.5 ?自定義vim使用環(huán)境
1、臨時設(shè)置
[root@xuegod63 ~]# vim a.txt?
:set nu ?設(shè)置行號
:set nonu 取消設(shè)置行號
:noh ??取消高亮顯示
2茉帅、永久設(shè)置環(huán)境
vim /etc/vimrc ?#設(shè)置后會影響到系統(tǒng)所有的用戶
~/.vimrc ??????#在用戶的家目錄下叨叙,創(chuàng)建一個.vimrc。這樣只影響到某一個用戶堪澎,沒有自己建一個
例1:臨時定制vim開啟顯示行號功能
[root@xuegod63 ~]# echo "set nu"?> ?/root/.vimrc
[root@xuegod63 ~]# vim ?/etc/passwd???#發(fā)現(xiàn)默認(rèn)已經(jīng)有行號了
3擂错、vim打開多個文件
方法1:以上下形勢,打開兩個文檔
[root@xuegod63 ~]# vim -o /etc/passwd /etc/hosts
注:輸入 ?:qa 一次退出所有打開的文件
方法2:以左右方式打開兩個文檔
[root@xuegod63 ~]# vim -O /etc/passwd /etc/hosts
注:ctrl+ww ?在兩文檔之間進(jìn)行切換編輯樱蛤。大寫O左右分屏钮呀,小寫的o上下分屏
比較兩個文件內(nèi)容
[root@xuegod63 ~]# cp /etc/passwd mima.txt
[root@xuegod63 ~]# echo aaa >> mima.txt
方法1:
[root@xuegod63 ~]# diff /etc/passwd mima.txt
40a41
> aaa
方法2:
[root@xuegod63 ~]# vimdiff /etc/passwd mima.txt
4.1.6 ?其它編輯器
nano編輯器
emacs編輯器
GHOME編輯器gedit
例:
[root@xuegod63 ~]# gedit /etc/passwd
4.1.7 ?實(shí)戰(zhàn)1:解決上傳windows中文文檔亂碼
實(shí)驗(yàn)環(huán)境:centos8 現(xiàn)在系統(tǒng)默認(rèn)使用的語言是漢語。(系統(tǒng)中必須安裝好中文包)昨凡。
將同目錄下“aaa此文件在windows下打開正常-到linux下vim打開是亂碼.txt”上傳到Linux服務(wù)器上爽醋。使用ssh遠(yuǎn)程連接到Linux上,使用vim打開顯示亂碼便脊。
原因:編碼的問題
通過iconv命令轉(zhuǎn)碼 ??
參數(shù):
-f, --from-code=名稱 原始文本編碼
-t, --to-code=輸出編碼
-o, --output=FILE 輸出文件名
[root@xuegod63 ~]# mkdir test??#創(chuàng)建一個測試目錄
[root@xuegod63 ~]# cd test/
將測試的文件上傳到Linux服務(wù)器上:
[root@xuegod63 ~]# iconv -f gb2312 ?-t utf8 aaa此文件在windows下打開正常-到linux下vim打開是亂碼.txt ?-o abc.txt
[root@xuegod63 ~]# cat abc.txt
#!/bin/bash
echo "學(xué)神IT"
4.2 ?實(shí)戰(zhàn):在Centos6/RHEL6上恢復(fù)ext4文件系統(tǒng)下誤刪除的文件
[root@xuegod63 ~]# rm -rf /????#這個可以執(zhí)行成功嗎蚂四? ??執(zhí)行不成功的,
rm: 在"/" 進(jìn)行遞歸操作十分危險
rm: 使用 --no-preserve-root 選項(xiàng)跳過安全模式
[root@xuegod63 ~]# rm -rf /*????#這個可以執(zhí)行成功。
ext4文件系統(tǒng)上刪除文件遂赠,可以恢復(fù): extundelete 久妆,ext3恢復(fù)使用:ext3grep
windows恢復(fù)誤刪除的文件: ?final data v2.0 漢化版 ?和 ?easyrecovery??
xfs文件系統(tǒng)上刪除文件,暫時沒有太好的辦法進(jìn)行完全恢復(fù)跷睦,需要找專業(yè)數(shù)據(jù)恢復(fù)公司
擴(kuò)展:
Linux文件系統(tǒng)由三部分組成:文件名筷弦,inode,block
windows也由這三部分組成送讲。
a.txt ?-->inode ?????????????--> block
文件名 ??????存放文件元數(shù)據(jù)信息 ??????真正存放數(shù)據(jù)
查看文件文件名:
[root@xuegod63 ~]# cp /etc/passwd a.txt
[root@xuegod63 ~]# ls a.txt
a.txt
查看inode號:
常識: 每個文件奸笤,有一個inode號。
[root@xuegod63 ~]# ls -i a.txt
440266 a.txt
查看inode中的文件屬性; ?通過stat命令查看inode中包含的內(nèi)容
[root@xuegod63 ~]# stat a.txt ??#查看inode信息:
[root@xuegod63 ~]# ls -l a.txt
-rw-r--r-- 1 root root 1720 Oct 25 10:21 a.txt
block塊:真正存儲數(shù)據(jù)的地方
邏輯刪除:
為什么刪除比復(fù)制快哼鬓?
誤刪除文件后监右,第一件事要做什么?异希?健盒? ?你不心刪除把存了幾十年的大片刪除了。
避免誤刪除的文件內(nèi)容被覆蓋称簿。 如何避免扣癣?
卸載需要恢復(fù)文件的分區(qū)或以只讀的方式掛載
4.2.2 ?實(shí)戰(zhàn):在ext4文件系統(tǒng)上恢復(fù)被誤刪除的文件
下載extundelete
http://sourceforge.net/????開源軟件發(fā)布中心
準(zhǔn)備測試分區(qū):
先添加一塊硬盤
[root@xuegod63 /]# fdisk /dev/sdb ?#創(chuàng)建一個sdb1分區(qū)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
?????????switch off the mode (command 'c') and change display units to
?????????sectors (command 'u').
Command (m for help):p???#查看現(xiàn)有分區(qū)表
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b8b35
???Device Boot ?????Start ????????End ?????Blocks ??Id ?System
/dev/sda1 ??* ??????????1 ?????????26 ?????204800 ??83 ?Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 ?????????????26 ???????1301 ???10240000 ??83 ?Linux
/dev/sda3 ???????????1301 ???????1428 ????1024000 ??82 ?Linux swap / Solaris
Command (m for help):n???#創(chuàng)建一個新分區(qū)
Command action
???e ??extended
???p ??primary partition (1-4)
p??#創(chuàng)建一個主分區(qū)
Selected partition 4
First cylinder (1428-2610, default 1428):
Using default value 1428
Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610):+1G ?#指定分區(qū)大小
Command (m for help):?w??#保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@xuegod63 ~]#reboot
或
[root@xuegod63 ~]# partx -a /dev/sdb ?#獲得新分區(qū)表
擴(kuò)展:
如果在根下刪除文件了,想恢復(fù)憨降,怎么辦父虑?
方法1: 立即斷電,然后把磁盤以只讀方式授药,掛載到另一個電腦中進(jìn)行恢復(fù)
方法2:把extundelete在虛擬機(jī)上(虛擬機(jī)系統(tǒng)要和服務(wù)器版本一樣)士嚎,提前安裝好后再復(fù)制到U盤中,把U盤插入服務(wù)器悔叽,恢復(fù)時莱衩,恢復(fù)的文件要保存到U盤中,(不要讓恢復(fù)的數(shù)據(jù)寫到/下娇澎,那樣會覆蓋之前刪除的文件)
使用新的分區(qū)表:
[root@xuegod63 /]# mkdir /tmp/sdb1?????#創(chuàng)建掛載點(diǎn)
[root@xuegod63 ~]# mkfs.ext4/dev/sdb1????#格式化
[root@xuegod63 ~]# mount /dev/sdb1 /tmp/sdb1???#掛載
4.2.3準(zhǔn)備測試環(huán)境
復(fù)制一些測試文件笨蚁,然后把這些文件再刪除,然后演示恢復(fù):
[root@xuegod63 ~]# cp /etc/passwd /tmp/sdb1
[root@xuegod63 ~]# cp /etc/hosts /tmp/sdb1
[root@xuegod63 ~]# echo aaa > a.txt
[root@xuegod63 ~]# mkdir -p /tmp/sdb1/a/b/c
[root@xuegod63 ~]# cp a.txt /tmp/sdb1/a
[root@xuegod63 ~]# cp a.txt /tmp/sdb1/a/b
[root@xuegod63 ~]# touch /tmp/sdb1/a/b/kong.txt
安裝tree命令:
[root@xuegod63 ~]# rpm -ivh /mnt/Packages/tree-1.5.3-2.el6.x86_64.rpm
[root@xuegod63 ~]# tree /tmp/sdb1
/tmp/sdb1/
├── a
│?? ├── a.txt
│?? └── b
│?? ????├── a.txt
│?? ????├── c ?#空目錄
│?? ????└── kong.txt ?#空文件
├── hosts
├── lost+found
└── passwd
lost+found
使用標(biāo)準(zhǔn)的ext3/ext4檔案系統(tǒng)格式才會產(chǎn)生的一個目錄趟庄,目的在于當(dāng)檔案系統(tǒng)發(fā)生錯誤時括细, 將一些遺失的片段放置到這個目錄下。
可以刪除 rm -rf ?lost+found
可以創(chuàng)建 mklost+found
刪除文件:
[root@xuegod63 ~]# cd /tmp/sdb1/
[root@xuegod63 sdb1]# ls
a ?hosts ?lost+found ?passwd
[root@xuegod63 sdb1]# rm -rf a hosts passwd
誤刪除文件后戚啥,第一件事要做什么勒极??虑鼎?
如何避免誤刪除的文件內(nèi)容被覆蓋辱匿?键痛??
卸載需要恢復(fù)文件的分區(qū):或以只讀的方式掛載
[root@localhost ~]#cd /root
[root@localhost ~]# umount /tmp/sdb1
4.2.4 ?安裝extundelet??
上傳extundelete到linux中:
從windows上傳extundelete文件到linux匾七,安裝xmanager ?v5 ??或者CRT
[root@xuegod63 ~]# rpm -ivh /mnt/Packages/lrzsz-0.12.20-27.1.el6.x86_64.rpm ?
安裝后絮短,就有了rz命令和sz命令
rz : 上傳windows中的文件到linux
sz?文件名 :下載昨忆,將linux中的文件傳到windows
解壓并安裝extundelet
[root@centos63~]#mount /dev/sr0 /mnt
[root@centos63~]# vim /etc/yum.repos.d/Centos-6.repo
[CentOS6]
name=CentOS-server
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@xuegod63]#?yum -y?install e2fsprogs-devel gcc gcc-c++ gcc-g77
[root@xuegod63 extundelete-0.2.4]# tar xf extundelete-0.2.4.tar.bz2
[root@xuegod63 ~]# cd extundelete-0.2.4
[root@xuegod63 extundelete-0.2.4]# ./configure ??#檢查系統(tǒng)安裝環(huán)境
[root@xuegod63 extundelete-0.2.4]# make??-j ?4 ?#編譯丁频,把源代碼編譯成可執(zhí)行的二進(jìn)制文件。
-j 4 ??使用4進(jìn)程同時編譯邑贴,提升編譯速度 或 使用4核CPU同時編譯席里。
[root@xuegod63 extundelete-0.2.4]# make install??#安裝
install 和cp 有什么區(qū)別?
install 復(fù)制時可以指定權(quán)限 ?cp不可以
例:
[root@xuegod63 ~]# install -m 777 /bin/find /opt/find
[root@xuegod63 ~]# ll /opt/
4.2.5 ?恢復(fù)數(shù)據(jù)
方法1:通過inode結(jié)點(diǎn)恢復(fù)
方法二:通過文件名恢復(fù)
方法三:恢復(fù)某個目錄拢驾,如目錄a下的所有文件:
方法四:恢復(fù)所有的文件
[root@xuegod63 ~]# umount /tmp/sdb1/
[root@xuegod63 ~]# mkdir test??#創(chuàng)建一個目錄使用于存放恢復(fù)的數(shù)據(jù)
[root@xuegod63 ~]# cd test/
方法1:
通過inode結(jié)點(diǎn)查看被刪除的文件名字:
[root@xuegod63 test]# extundelete /dev/sdb1 --inode 2
. ???????????????????????????????????????????????2
lost+found ???????????????????????????????????????11
passwd ???????????????????????????????????????????12 ????????????Deleted
hosts ????????????????????????????????????????????13 ????????????Deleted
a ????????????????????????????????????????????????7313 ??????????Deleted
擴(kuò)展:ext4文件系統(tǒng)的分區(qū)根目錄的inode值為2奖磁,xfs分區(qū)根目錄的inode值為64
[root@xuegod63 test]# ls -id /???#xfs文件系統(tǒng)
64/
[root@xuegod63 test]# mount /dev/sdb1 /tmp/sdb1/
[root@xuegod63 test]# ls -id /tmp/sdb1/
2/tmp/sdb1/
[root@xuegod63 test]# umount /tmp/sdb1/
方法1:通過inode結(jié)點(diǎn)恢復(fù)
[root@xuegod63 test]# extundelete /dev/sdb1 --restore-inode12
NOTICE: Extended attributes are not restored.
Loading filesystem metadata ... 9 groups loaded.
Loading journal descriptors ... 63 descriptors loaded.
[root@xuegod63 test]# ls
RECOVERED_FILES
[root@xuegod63 test]# diff /etc/passwd RECOVERED_FILES/file.12??
#沒有任何輸出,說明一樣
方法二繁疤,通過文件名恢復(fù)
[root@xuegod63 test]# extundelete /dev/sdb1 --restore-file hosts
[root@xuegod63 test]# diff /etc/passwd RECOVERED_FILES/hosts??
#沒有任何輸出咖为,說明一樣
方法三:恢復(fù)某個目錄,如目錄a下的所有文件:
[root@xuegod63 test]# extundelete /dev/sdb1 --restore-directory a
[root@xuegod63 test]# tree RECOVERED_FILES/a/
RECOVERED_FILES/a/
├── a.txt
└── b
下面是原來的目錄結(jié)構(gòu):
[root@xuegod63 ~]# tree /root/sdb1-back/a/
/root/sdb1-back/a/
└── b
????├── a.txt
????├── c
└── kong.txt
方法四:恢復(fù)所有的文件
[root@centos6 test]# rm -rf RECOVERED_FILES/
[root@xuegod63 test]# extundelete /dev/sdb1 --restore-all
[root@centos6 test]# tree RECOVERED_FILES/
刪除前后的數(shù)據(jù):
eextundelet在恢復(fù)文件的時候能不能自動創(chuàng)建空文件和目錄稠腊?
答:不能躁染。
4.3 ?使用xfs_undelete恢復(fù)誤刪除文件
XFS文件系統(tǒng)的取消刪除工具——xfs_undelete。
xfs_undelete嘗試恢復(fù)xfs文件系統(tǒng)中標(biāo)記為已刪除的所有文件架忌。
恢復(fù)的文件存儲在子目錄中的另一個文件系統(tǒng)中吞彤,默認(rèn)情況下,相當(dāng)于當(dāng)前目錄xfs_?undelete叹放。文件名無法恢復(fù)饰恕,它被作為刪除時間、inode編號和猜測的文件擴(kuò)展名许昨。
環(huán)境需求
先添加一塊硬盤懂盐,后面會用到
xfs_undelete是一個小的Tcl腳本褥赊,因此需要一個Tcl解釋器糕档。它使用了Tcl-8.6的一些特性,所以至少需要這個版本拌喉,tclib包用于解析命令行速那。
下載tcl8.6,tcllib和xfs_undelete
Tcl download | SourceForge.net
https://core.tcl-lang.org/tcllib/technote/cd3a11c3065120d491009e64a19f7676176045cd
https://github.com/ianka/xfs_undelete
上傳軟件包到centos7系統(tǒng)
安裝tcl
[root@xuegod63 ~]# tar xvf tcl8.6.11-src.tar.gz
[root@xuegod63 ~]# cd tcl8.6.11/unix/
[root@xuegod63 ~]#./configure
[root@xuegod63 ~]# echo $?
[root@xuegod63 ~]# make -j?4 && make install
[root@xuegod63 ~]# echo $?
時間很長
使tclsh全局生效加入path變量
[root@xuegod63 ~]# mv /root/tcl8.6.11 /root/tcl
[root@xuegod63 ~]# vim /etc/profile??# 在文件最后追加以下內(nèi)容尿背,永久生效
export PATH=/root/tcl/unix/:$PATH
[root@xuegod63 ~]# source ?/etc/profile???#重新加載配置文件端仰,使用配置生效
[root@xuegod63 ~]# echo $PATH
安裝tcllib
[root@xuegod63 ~]# tar xf tcllib-1.20.tar.gz
[root@xuegod63 ~]# cd tcllib-1.20/
[root@xuegod63 tcllib-1.20]# ./configure
[root@xuegod63 tcllib-1.20]# echo $?
[root@xuegod63 tcllib-1.20]# make -j 4 && make install
[root@xuegod63 tcllib-1.20]# echo $?
安裝xfs_undelete
[root@xuegod63 tcllib-1.20]# cd
[root@xuegod63 ~]# unzip xfs_undelete-master.zip
[root@xuegod63 ~]# cd xfs_undelete-master/
[root@xuegod63 xfs_undelete-master]# ./xfs_undelete -h ???#查看幫助信息
掛載點(diǎn)創(chuàng)建一些測試文件,文件里要有內(nèi)容田藐,然后刪除幾個
[root@xuegod63 xfs_undelete-master]# cd
[root@xuegod63 ~]# gdisk /dev/sdb
[root@xuegod63 ~]# mkfs.xfs /dev/sdb1
[root@xuegod63 ~]# mkdir /testsdb1
[root@xuegod63 ~]# mount /dev/sdb1 /testsdb1
[root@xuegod63 ~]# mkdir /testsdb1/kong
[root@xuegod63 ~]# touch /testsdb1/kong.txt
[root@xuegod63 ~]# cp /etc/passwd /testsdb1/
[root@xuegod63 ~]# cp /etc/passwd /testsdb1/kong
[root@xuegod63 ~]# echo "hello world" > /testsdb1/hello.txt
[root@xuegod63 ~]# ls ?/testsdb1
[root@xuegod63 ~]# rm -rf /testsdb1/*
[root@xuegod63 testsdb1]# cd
[root@xuegod63 ~]# umount /testsdb1
[root@xuegod63 ~]# cd xfs_undelete-master/
[root@xuegod63 xfs_undelete-master]# ./xfs_undelete /dev/sdb1
[root@xuegod63 xfs_undelete-master]# cd xfs_undeleted/
[root@xuegod63 xfs_undeleted]# ls
[root@xuegod63 xfs_undeleted]# head 2021-06-08-11-02_68.txt
hello world
直接執(zhí)行腳本首先會以只讀的方式重新掛載荔烧,然后恢復(fù)吱七,恢復(fù)的不是原文件名,但是內(nèi)容是一樣的鹤竭。
注意需要進(jìn)入目錄才能看到
注意:不會恢復(fù)目錄和空文件
也可以恢復(fù)數(shù)據(jù)到指定的目錄
[root@xuegod63 xfs_undeleted]# cd ..
[root@xuegod63 xfs_undelete-master]# ./xfs_undelete ?-o /opt /dev/sdb1
4.4??實(shí)戰(zhàn):使用xmanager等遠(yuǎn)程連接工具管理Linux
4.4.1 ?Linux下常用遠(yuǎn)程連接工具介紹
4.4.2 ?xmanager 使用方法
安裝以后打開
1踊餐、xshell使用方法
例1:連接一臺新的服務(wù)器
例2:調(diào)整xshell字體大小
例3:調(diào)整rz和sz命令的默認(rèn)路徑
例4:解決Xshell中小鍵盤無法打出數(shù)字的問題
例5:解決Xshell不能使用退格、刪除鍵的問題
2臀稚、xftp使用方法
例1:上傳一個文件夾到Linux服務(wù)器上
3吝岭、xstart使用方法
方法1:使用xshell直接運(yùn)行圖形界面的程序
例1:[root@xuegod63 ~]# gnome-terminal
例2:[root@xuegod63 ~]# firefox &
方法2:使用xstart調(diào)用桌面
注:使用MK給的xmanger5安裝后,后期運(yùn)行吧寺,提示更新到新版本窜管, 你不要更新,更新稚机,有可能序列號就不能使用了幕帆。
https://www.netsarang.com/zh/free-for-home-school/
也可以下載官方免費(fèi)版
總結(jié):
??4.1 ?vim的使用
??4.2 ?實(shí)戰(zhàn):恢復(fù)ext4文件系統(tǒng)下誤刪除的文件
??4.3 ?實(shí)戰(zhàn):使用xfs_undelete恢復(fù)誤刪除文件
??4.4??實(shí)戰(zhàn):使用xmanager等遠(yuǎn)程連接工具管理Linux
更多學(xué)習(xí)資料以及視頻資料請移步至公眾號【學(xué)神來啦】