天天看點

2.23——2.25find指令(上中下);2.26 檔案名字尾

2.23 find指令(上)

快捷鍵:

Ctrl + l  :清屏

Ctrl + d :退出終端(相當于執行了:exit 或logout)

Ctrl + c : 強制中斷

Ctrl + u : 在指令輸入行,删除光标前的字元串

Ctrl + e :  光标移到末尾

Ctrl + a :  光标移到開始

which :搜尋指令檔案(從echo $PATH環境變量下的目錄查找)

find :搜尋檔案

1. find 精準搜尋:find 搜尋路徑 -name "精準關鍵詞"

[root@hao-01 ~]# find /root/ -name "mulu1.txt"

clipboard.png

2. find 模糊搜尋:find  搜尋路徑 -name "模糊關鍵詞*"

關鍵詞後面加 * 就是把有帶關鍵詞的檔案和目錄都顯示出來!

[root@hao-01 ~]# find /root/ -name "mulu*"

3. find 隻搜尋帶有關鍵詞的 目錄 :

find  搜尋路徑 -type d -name "模糊關鍵詞*"

[root@hao-01 ~]# find /root/ -type d -name "mulu*"

4. find 隻搜尋帶有關鍵詞的 檔案:

find  搜尋路徑 -type f -name "模糊關鍵詞*"

[root@hao-01 ~]# find /root/ -type f -name "mulu*"

5. find 搜尋指定的檔案類型:

檔案類型包括:

f  :(-)普通文檔檔案和二進制檔案

l  :軟連結檔案(相當于Windows快捷方式)

s :通信檔案                 

c  : 字元串裝置(滑鼠鍵盤)

b :塊裝置檔案(CD光牒,磁盤)

2.24 find指令(中)

1. 在檔案末尾追加一行内容:echo "追加内容"  >>  檔案

[root@hao-01 ~]# echo "hao" >> 1.txt

stat :檢視檔案詳細資訊

stat 跟檔案名

atime :最近通路  (cat 指令檢視檔案内容 ; atime會變)

mtime:最近更改  (更改:檔案的内容;mtime會變)

ctime :最近改動  (改動:權限或inode或檔案名或時間等;ctime會變)

提示:更改檔案内容,mtime時間會變,ctime也跟着會變!

搜尋指定檔案的 atime(最近通路)

1. find 搜尋 (atime) cat檢視就是通路時間 大于1天時間的檔案:find 路徑  -type f -atime +1

[root@hao-01 ~]# find /root/ -type f -atime +1

2. find 搜尋 (atime) cat檢視就是通路時間 小于1天時間的檔案:find 路徑  -type f -atime -1

[root@hao-01 ~]# find /root/ -type f -atime -1

搜尋指定檔案的 mtime(最近更改)

1. find 搜尋(mtime) 建立或修改時間大餘1天時間的檔案:

find 路徑  -type f -mtime +1

[root@hao-01 ~]# find /root/ -type  f  -mtime  +1

2. find 搜尋(mtime)建立或修改時間小少1天時間的檔案:

find 路徑  -type f -mtime -1

[root@hao-01 ~]# find  /root/  -type  f  -mtime  -1

搜尋指定檔案的 ctime (最近更改)

1. find 搜尋(ctime)更改權限或inode或檔案名或時間等,大餘1天時間的檔案:find 路徑  -type f -ctime +1

[root@hao-01 ~]# find  /root/  -type  f  -ctime  +1

2. find 搜尋(ctime)更改權限或inode或檔案名或時間等,小餘1天時間的檔案:find 路徑  -type f -ctime -1

[root@hao-01 ~]# find  /root/  -type  f  -ctime  -1

find 多個判斷條件搜尋的:

-type f         :指定搜尋的是普通文檔檔案

-atime -1     :指定搜尋的是建立或修改時間,小于一天

-name "1.txt*" :指定搜尋的是關鍵詞

[root@hao-01 ~]#  find /root/ -type f -mtime -1 -name "1.txt*"

2.25 find指令(下)

根據inode可以查找檔案的硬連結: find  /(根路徑) -inum  inode号

1. 根據原檔案的inode号,可以查找原檔案的硬連結:

[root@hao-01 ~]# find / -inum 33589250

2. 搜尋一小時内建立或修改的檔案:

-mmin :指定分鐘的意思 -60就是小于60分鐘,60分鐘内!

[root@hao-01 ~]# find /root/ -type f -mmin -60

3. 搜尋一個小時内建立或修改的檔案,同時搜尋到的執行ls -l

[root@hao-01 ~]# find /root/ -type f -mmin -60 -exec ls -l ;

4. 搜尋一個小時内建立或修改的檔案,同時搜到的執行添加字尾名

[root@hao-01 ~]# find /root/ -type f -mmin -60 -exec mv {} {}.bak \;  

5. 指定搜尋檔案大于10k:-size +10k

[root@hao-01 ~]# find /root/ -type f -size +10k -exec ls -lh {} \;

6. 指定搜尋檔案大于10M:-size +10M

[root@hao-01 ~]# find /root/ -type f -size +10M -exec ls -lh {} \;

2.26 檔案名字尾

檔案名的字尾,不能代表檔案類型

繼續閱讀