Find
locate 搜索命令 使用:
#yum install -y mlocate 安裝
updatedb 生成db數據庫,服務器不建議在工作時間生成,使用計劃任務在凌晨啓動
#find /etc/ -name 'sshd*' 模糊搜索,搜索/etc目錄下name爲sshd的文件或目錄 #find /etc/ -type d -name "sshd*" 模糊搜索,只搜索/etc目錄下name爲sshd的目錄 #find /etc/ -type f -name "sshd*" 模糊搜索,只搜索/etc目錄下name爲sshd的文件
-type l 爲連接文件
-type b 爲block塊設備
#stat 2.txt 查看 2.txt的time狀態信息
參數:
atime = access time 訪問時間
mtime = modify time 創建(修改)時間
ctime = change time 改動時間
更改了文件內容,ctime一定會發生改變
查看文件內容,access會發生改變
實例:
#find /etc/ -type f -mtime -1 #一天以內/etc目錄下修改過的文件 #find /etc/ -type f -mtime +1 #一天前的/etc目錄下修改過的文件 #find /etc/ -type f -mtime +1 -name "*.conf" #一天前的/etc目錄下名爲.conf 且修改過的文件 #find /etc/ -type f -o -mtime +1 -o -name "*.conf" #一天前的/etc目錄下名爲.conf 且修改過的文件 如上兩個“-o”均是或的意思 #find /etc/ -type f -mmin -200 #200分鐘以內/etc目錄下修改過的文件
#find /etc/ -type f -mmin -200 -exec ls -l {} \; #200分鐘以內/etc目錄下修改過的文件, -exec 是指:執行 ls -l 命令, {} 表示對列出的結果再次交給ls一條條的執行
#find /etc/ -type f -mmin -200 -exec mv {} {}.bak \; #然後對符合條件的文件全部改名爲.bak 在日常工作中會用到find去查找Size大於多少多少的文件或者目錄時
#find /etc/ -type f -size -10M -exec ls -lh {} \; #列出來在/etc目錄下 類型爲文件且大於10M的 並ls -lh顯示其詳細信息