本人從事IT行業(yè)已有十多年,有著豐富的實(shí)戰(zhàn)經(jīng)驗(yàn),總結(jié)了大量的學(xué)習(xí)方法,更是積累了很多的學(xué)習(xí)資料,很高興能在這里跟大家交流學(xué)習(xí),希望能在這里跟大家共同進(jìn)步和成長(zhǎng)!
全套學(xué)習(xí)資料移步至公眾號(hào)【學(xué)神來(lái)啦】
?本節(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是同一個(gè)軟件包安裝的嗎?
答:NO,vim是vi的增加版,最明顯的區(qū)別就是vim可以語(yǔ)法加亮,它完全兼容vi
查看一個(gè)命令,是哪個(gè)軟件包,安裝的:
[root@xuegod63 ~]# rpm -qf /usr/bin/vim
[root@xuegod63 ~]# which vim
[root@xuegod63?~]# rpm -qf `which vim` ??#`反引號(hào),esc按鍵下的鍵,反引號(hào)中可執(zhí)行命令
[root@xuegod63?~]# rpm -qf $(which vi) ??#$(可執(zhí)行命令)
$() 與`` 都可以進(jìn)行命令替換,命令替換與變量替換差不多,都是用來(lái)重組命令行的,先完成引號(hào)里的命令行,然后將其結(jié)果替換出來(lái),再重組成新的命令行
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鍵,再輸入冒號(hào): ?????----命令行模式(Command-line?mode)
例1從編輯模式到命令行模式怎樣切換?
編輯模式->esc->命令模式->:?->命令行模式
注意在命令模式下,輸入命令無(wú)效時(shí),檢查下輸入法是不是中文輸入法,切換為英文輸入法
例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 向后刪除一個(gè)字符等同于delete
X 向前刪除一個(gè)字符 ????
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來(lái)進(jìn)行向上向下查找,并且vim會(huì)對(duì)查找到的內(nèi)容進(jìn)行高亮顯示,取消高亮用 :noh
/^d ?----尖括號(hào)^意思表示以什么開頭 ,查找以字母d開頭的內(nèi)容
/bash$ ??-----$意思表示以什么結(jié)尾,查找以字母bash結(jié)尾的內(nèi)容
vim + /etc/passwd??打開文件后,光標(biāo)會(huì)自動(dòng)位于文件的最后一行。 了解一下這個(gè)技巧。
vim +23 /etc/passwd??打開文件后,光標(biāo)會(huì)自動(dòng)位于文件的第23行,方便后期排錯(cuò)。如:服務(wù)器啟動(dòng)報(bào)錯(cuò),第23,有語(yǔ)法錯(cuò)誤。使用vim +23 /etc/passwd可以快速定位到23行。
分享心得:我更喜歡vim打開文件,然后按G,跳到最后。 因這個(gè)vim + a.txt ?技巧不常用,過一段時(shí)間肯定會(huì)忘。Linux中有太多的小技巧,大家應(yīng)該記那些常用的。
2、在正常模式對(duì)文本進(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 替換,或者說用來(lái)修改一個(gè)字符
總結(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ù)器配置文件的時(shí)候,需要進(jìn)行多行注釋,會(huì)使用Visual模式。
1、進(jìn)入Visual模式的批量刪除,方法如下:
刪除:再按ctrl+v 進(jìn)入可視塊模式;向下或向上移動(dòng)光標(biāo)?;選中部分內(nèi)容,然后按d, 就會(huì)刪除注釋符號(hào)。
例:將sshd_config?文件中17行到20行前面的#號(hào)刪除
[root@xuegod63 ~]# vim /etc/ssh/sshd_config
改:
?為:
2、進(jìn)入Visual模式的批量修改,方法如下:
1)、ctrl+v 進(jìn)入列編輯模式
2)、向下或向上移動(dòng)光標(biāo),把需要注釋、編輯的行的開頭選中起來(lái)
4)、然后按大寫的I
5)、再插入注釋符或者你需要插入的符號(hào),比如"#"
6)、再按Esc,就會(huì)全部注釋或添加了
例:在sshd_config?文件中17行到20行前面加一個(gè)#號(hào)
[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)行修改時(shí)的狀態(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)用外部文件或命令
語(yǔ)法:在命令行模式下輸入: !+命令
例:在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è)符合要求的詞 ??(/g全部)
[root@xuegod63 ~]# vim a.txt
:1,3 s/bin/xuegod ????#替換第1到3行中出現(xiàn)的第一個(gè)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 ,先在文件中隨意插入幾個(gè)do 和DO 字符
:% s/do/xuegod/g?????#將文本中所有的do替換成xuegod
:% s/do/xuegod/gi ????#將文本中所有的do替換成xuegod, 并且忽略do的大小寫
:% s@xuegod@do@g #將文本中所有的xuegod替換成do,替換時(shí),也可以使用@做分隔符
4.1.5 ?自定義vim使用環(huán)境
1、臨時(shí)設(shè)置
[root@xuegod63 ~]# vim a.txt?
:set nu ?設(shè)置行號(hào)
:set nonu 取消設(shè)置行號(hào)
:noh ??取消高亮顯示
2、永久設(shè)置環(huán)境
vim /etc/vimrc ?#設(shè)置后會(huì)影響到系統(tǒng)所有的用戶
~/.vimrc ??????#在用戶的家目錄下,創(chuàng)建一個(gè).vimrc。這樣只影響到某一個(gè)用戶,沒有自己建一個(gè)
例1:臨時(shí)定制vim開啟顯示行號(hào)功能
[root@xuegod63 ~]# echo "set nu"?> ?/root/.vimrc
[root@xuegod63 ~]# vim ?/etc/passwd???#發(fā)現(xiàn)默認(rèn)已經(jīng)有行號(hào)了
3、vim打開多個(gè)文件
方法1:以上下形勢(shì),打開兩個(gè)文檔
[root@xuegod63 ~]# vim -o /etc/passwd /etc/hosts
注:輸入 ?:qa 一次退出所有打開的文件
方法2:以左右方式打開兩個(gè)文檔
[root@xuegod63 ~]# vim -O /etc/passwd /etc/hosts
注:ctrl+ww ?在兩文檔之間進(jìn)行切換編輯。大寫O左右分屏,小寫的o上下分屏
比較兩個(gè)文件內(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)使用的語(yǔ)言是漢語(yǔ)。(系統(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)建一個(gè)測(cè)試目錄
[root@xuegod63 ~]# cd test/
將測(cè)試的文件上傳到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 /????#這個(gè)可以執(zhí)行成功嗎? ??執(zhí)行不成功的,
rm: 在"/" 進(jìn)行遞歸操作十分危險(xiǎn)
rm: 使用 --no-preserve-root 選項(xiàng)跳過安全模式
[root@xuegod63 ~]# rm -rf /*????#這個(gè)可以執(zhí)行成功。
ext4文件系統(tǒng)上刪除文件,可以恢復(fù): extundelete ,ext3恢復(fù)使用:ext3grep
windows恢復(fù)誤刪除的文件: ?final data v2.0 漢化版 ?和 ?easyrecovery??
xfs文件系統(tǒng)上刪除文件,暫時(shí)沒有太好的辦法進(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號(hào):
常識(shí): 每個(gè)文件,有一個(gè)inode號(hào)。
[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塊:真正存儲(chǔ)數(shù)據(jù)的地方
邏輯刪除:
為什么刪除比復(fù)制快?
誤刪除文件后,第一件事要做什么??? ?你不心刪除把存了幾十年的大片刪除了。
避免誤刪除的文件內(nèi)容被覆蓋。 如何避免?
卸載需要恢復(fù)文件的分區(qū)或以只讀的方式掛載
4.2.2 ?實(shí)戰(zhàn):在ext4文件系統(tǒng)上恢復(fù)被誤刪除的文件
下載extundelete
http://sourceforge.net/????開源軟件發(fā)布中心
準(zhǔn)備測(cè)試分區(qū):
先添加一塊硬盤
[root@xuegod63 /]# fdisk /dev/sdb ?#創(chuàng)建一個(gè)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)建一個(gè)新分區(qū)
Command action
???e ??extended
???p ??primary partition (1-4)
p??#創(chuàng)建一個(gè)主分區(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: 立即斷電,然后把磁盤以只讀方式,掛載到另一個(gè)電腦中進(jìn)行恢復(fù)
方法2:把extundelete在虛擬機(jī)上(虛擬機(jī)系統(tǒng)要和服務(wù)器版本一樣),提前安裝好后再?gòu)?fù)制到U盤中,把U盤插入服務(wù)器,恢復(fù)時(shí),恢復(fù)的文件要保存到U盤中,(不要讓恢復(fù)的數(shù)據(jù)寫到/下,那樣會(huì)覆蓋之前刪除的文件)
使用新的分區(qū)表:
[root@xuegod63 /]# mkdir /tmp/sdb1?????#創(chuàng)建掛載點(diǎn)
[root@xuegod63 ~]# mkfs.ext4/dev/sdb1????#格式化
[root@xuegod63 ~]# mount /dev/sdb1 /tmp/sdb1???#掛載
復(fù)制一些測(cè)試文件,然后把這些文件再刪除,然后演示恢復(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)格式才會(huì)產(chǎn)生的一個(gè)目錄,目的在于當(dāng)檔案系統(tǒng)發(fā)生錯(cuò)誤時(shí), 將一些遺失的片段放置到這個(gè)目錄下。
可以刪除 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?。骸∩蟼鱳indows中的文件到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)程同時(shí)編譯,提升編譯速度 或 使用4核CPU同時(shí)編譯。
[root@xuegod63 extundelete-0.2.4]# make install??#安裝
install 和cp 有什么區(qū)別?
install 復(fù)制時(shí)可以指定權(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ù)某個(gè)目錄,如目錄a下的所有文件:
方法四:恢復(fù)所有的文件
[root@xuegod63 ~]# umount /tmp/sdb1/
[root@xuegod63 ~]# mkdir test??#創(chuàng)建一個(gè)目錄使用于存放恢復(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ù)某個(gè)目錄,如目錄a下的所有文件:
[root@xuegod63 test]# extundelete /dev/sdb1 --restore-directory a
[root@xuegod63 test]# tree RECOVERED_FILES/a/
RECOVERED_FILES/a/
├── a.txt
└── b
下面是原來(lái)的目錄結(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ù)文件的時(shí)候能不能自動(dòng)創(chuàng)建空文件和目錄?
答:不能。
4.3 ?使用xfs_undelete恢復(fù)誤刪除文件
XFS文件系統(tǒng)的取消刪除工具——xfs_undelete。
xfs_undelete嘗試恢復(fù)xfs文件系統(tǒng)中標(biāo)記為已刪除的所有文件。
恢復(fù)的文件存儲(chǔ)在子目錄中的另一個(gè)文件系統(tǒng)中,默認(rèn)情況下,相當(dāng)于當(dāng)前目錄xfs_?undelete。文件名無(wú)法恢復(fù),它被作為刪除時(shí)間、inode編號(hào)和猜測(cè)的文件擴(kuò)展名。
環(huán)境需求
先添加一塊硬盤,后面會(huì)用到
xfs_undelete是一個(gè)小的Tcl腳本,因此需要一個(gè)Tcl解釋器。它使用了Tcl-8.6的一些特性,所以至少需要這個(gè)版本,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 $?
時(shí)間很長(zhǎng)
使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)建一些測(cè)試文件,文件里要有內(nèi)容,然后刪除幾個(gè)
[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í)行腳本首先會(huì)以只讀的方式重新掛載,然后恢復(fù),恢復(fù)的不是原文件名,但是內(nèi)容是一樣的。
注意需要進(jìn)入目錄才能看到
注意:不會(huì)恢復(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:連接一臺(tái)新的服務(wù)器
例2:調(diào)整xshell字體大小
例3:調(diào)整rz和sz命令的默認(rèn)路徑
例4:解決Xshell中小鍵盤無(wú)法打出數(shù)字的問題
例5:解決Xshell不能使用退格、刪除鍵的問題
2、xftp使用方法
例1:上傳一個(gè)文件夾到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)行,提示更新到新版本, 你不要更新,更新,有可能序列號(hào)就不能使用了。
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í)資料以及視頻資料請(qǐng)移步至公眾號(hào)【學(xué)神來(lái)啦】