find與locate搜尋命令

2021-12-29 20:12:04 字數 1544 閱讀 7991

locate :基於檔案資料庫搜尋速度快,支援模糊匹配.

-i 忽略大小寫

-n n 找到對應檔案後只顯示前n行

updatedb: locate資料庫生成,不過速度比較慢,需要遍歷檔案.

find : 實時檢索,精確匹配檔名,

格式: find [dir,...] [criteria (規則)]  [action...]

[action] 預設print

[criteria (規則)]:  預設當前目錄

1.根據檔名搜檢索:

-name  以檔名查詢,支援檔名統配* ?

例: find /etc -name "passwd"

-iname  不區分檔名大小寫

2.根據屬主,屬組檢索:

-user  find /home -user redhat

ls -l `find /home -user redhat`

-group 同上

-uid   使用者被刪除而檔案未被刪除 其檔案屬主uid

-gid

-nouesr    沒有使用者

-nogroup  沒有屬組

3.根據屬性檢索:

-type    型別  f d l s b c p 

-cnewer  屬性

-newer   內容

-size  根據檔案大小  [+/-]n 

特例:find /etc -size 1m  找到小於1m的檔案

2m表示精確為2m的檔案+ 1m 大於1m

4.根據許可權:

-perm  [-/]mode   +號不常用                   

find /tmp -perm 755 精確匹配

find /tmp -perm  -222   屬主,屬組,其他使用者許可權都要匹配

+222   同"/"有一類匹配即匹配

/777   許可權有一位許可權匹配就匹配

/001   匹配有執行許可權的檔案

5.根據檔案時間:

-atime 例: find /etc -atime +5 表示五天沒訪問的檔案."-5"表示天內訪問過的.

-mtime  用法同上

-ctime  用法同上

-amin  時間以分鐘為單位 用法同上

-mmin  用法同上

-cmin  用法同上

-anewer 例:find /etc -annewer /etc/passwd 訪問時間比passwd訪問更早的檔案

action :

-print 預設

-ls-ok  要求確認

-exec  command

find ./  -perm /001 -not -type d -exec chmod o-x {} \;

find ./ -name "[[:alpha:]][[:digit:]]" -exec mv {} {}.old \;

{} 表示之前找到的檔名

find -name "*.old"  | xargs chmod 755

本文出自 「魏巍的linux酒吧」 部落格

檔案搜尋命令find

1 路徑加檔名搜尋 find 查詢的是etc目錄下的以init為名字的檔案。加萬用字元後為模糊搜尋,只要檔名中含有init即可。查詢etc目錄下以init開頭的七位檔名。2 搜尋時不區分大小寫 iname 我們知道在windows系統中,檔名是不區分大小寫的,大寫和小寫是同乙個檔案。但是在linux...

4 1 linux搜尋命令 locate

檔案搜尋命令 locate 命令格式 locate 檔名 在後台資料庫中按檔名稱搜尋,搜尋的速度快。並不是新建完檔案後都會立刻更新的,mlocate資料庫是每天一更新,可以進行強制更新。強制更新命令 updatedb locate搜尋規則 locate配置檔案處在 etc updatedb.conf...

linux 檔案搜尋命令 find

命令名稱 find 命令所在路徑 bin find 執行許可權 所有使用者 語法 find 搜尋範圍 匹配條件 功能描述 檔案搜尋 乙個資料塊 512位元組 0.5k 1.find etc name init 在目錄 etc 中查詢檔案init iname 不區分大小寫 2.find size 20...