2.23-2.25 find命令
find搜尋檔案或路徑
一、常規用法:
當我們只知道目標檔案,但不知道具體路徑,只知道大概範圍時。
比如我想搜尋/etc/下的名字叫"sshd"相關的檔案
find /etc/ -name "sshd*"
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd
搜尋出了/etc/下與sshd相關的所有檔案和目錄
如果只想搜尋目錄,不要檔案,可以用"-type d"
find /etc/ -type d -name "sshd*"
如果只想搜尋檔案,不要目錄,可以用「-type f」
find /etc/ -type f -name "sshd*"
如果只想搜尋軟鏈結檔案,可能用「-type l」,搜sockt檔案用「-type s」,搜字串裝置用「-type c」,搜塊裝置檔案用「-type b」
二、find搜尋比較複雜的用法
語法:find [路徑] [引數]
-atime +n/-n : 最近訪問或執行時間大於/小於n天的檔案 (access time)
-mtime +n/-n : 最近更改,寫入時間大於/小於n天的檔案 (modify time),比如更改了檔案的內容
-ctime +n/-n :最近改動寫入、更改inode屬性(例如更改所有者、許可權或鏈結)時間大於/小於n天的檔案(change time)
因此,如果你更改了檔案的內容,ctime也一定會變。
例1:搜尋建立或更改檔案內容的時間在1天內的,且檔名為*.conf的
find / -type f -mtime -1 -name "*.conf"
例2:搜尋建立或更改檔案內容的,或更改時間在1天內的,或者檔名為*.conf的
find / -type f -o -mtime -1 -o -name "*.conf"
例3:通過搜尋某一inode號來查詢檔案的硬鏈結,可用-inum 引數
find / -inum 33583395
可得:/root/1_heard.txt
/tmp/1.txt.bak
例4:搜尋/root/目錄建立或更改檔案內容的時間在60分鐘以內的檔案,並且同時把它們列出來
find /root/ -type f -mmin -60 -exec ls -l {} \;
其中{}是列表出來的意思
例5:搜尋/root/目錄建立或更改檔案內容的時間在150分鐘以內的檔案,並且同時把它們列出來改名為原檔名.bak
find /root/ -type f -mmin -150 -exec mv {} {}.bak \;
find /root/ -type f -mmin -150#檢視下修改完之後所成果
/root/234/aminglinux.bak
/root/234/aminglinux111.bak
/root/2.txt.bak
例6:搜尋/root/目錄下,檔案大小大於10k/m的檔案
find /root/ -size +10k
其他搜尋命令
1、which 查詢可執行檔案的絕對路徑
which cat
/usr/bin/cat
2、whereis 查詢檔案,它是通過預先生成的乙個檔案列表庫去查詢跟給出的檔名相關的檔案 。
語法:whereis[-bmsu] [檔名稱]
-b:只找binary檔案
-m:只找在說明檔案manual路徑下的檔案
-s:只找source**檔案
-u:沒有說明檔的檔案
whereis ls
ls:/usr/bin/ls /usr/share/man/man1/ls.1.gz
3、locate查詢檔案 ,需要安裝
安裝:yum install mlocate -y
安裝後還不能馬上使用這個來查詢,得先使用updatedb命令立即生成(更新)這個庫。預設每週更新一次
updatedb
locate 2.txt
/root/2.txt
2.26.檔名字尾
linux檔案的字尾名並不代表他是什麼型別的檔案,我們可以自定義檔名和字尾,只不過是管理員通常會把相同型別的檔案定義成相同的字尾名,方便我們去區分,比如我們習慣把壓縮檔案習慣性命名為*.gz,配置檔案字尾名為*.conf,但是你也可以把其他檔案命名成.gz,也是可以的.
echo $lang
zh_ch.uft-8#系統預設語言顯示中文,前提是安裝系統時有中文支援。
tips:
快捷鍵:
ctrl+l清屏
ctrl+d退出乙個終端
ctrl+c停止執行這個命令
ctrl+u以游標位置為原點,往前刪
ctrl+e游標移到行尾
ctrl+a游標移到行首
stat 檢視檔案的具體資訊,比如大小,許可權,環境,塊,inode,最近訪問時間等
find命令及檔名字尾
常見的搜尋命令有 which whereis locate find。locate命令可以通過 yum install y mlocate 來安裝,如果在安裝成功,使用locate命令提示不可用,執行 updatedb 更新資料庫,保證資料的實時性。locate命令的格式為 locate 選項 檔名...
linux系統find命令 檔名字尾
2.23 2.24 2.25 find命令 find 搜尋檔案的命令which ls 從環境變數 echo path 中找的whereis ls 可以搜尋,搜的不全 安裝 locate root wangshuang 01 yum install y mlocate 模糊搜尋 locate 關鍵字 ...
9 2 find 檔名字尾 互傳檔案
root arslinux 01 find etc type f mtime 1 etc resolv.conf etc tuned active profile etc tuned profile mode 1小於1天,1大於1天,不能等於1 root arslinux 01 find etc t...