Linux 命令學習(2) find

2021-09-01 07:21:37 字數 4691 閱讀 7251

參考:

[b][size=medium]1. 格式[/size][/b]

find path  -option [ -print ] [ -exec -ok command ] {} \

-print: find命令將匹配的檔案輸出到標準輸出。

-exec: find命令對匹配的檔案執行該引數所給出的shell命令。相應命令的形式為'command' \;,注意和\;之間的空格。

-ok: 和-exec的作用相同,只不過以一種更為安全的模式來執行該引數所給出的shell命令,在執行每乙個命令之前,都會給出提示,讓使用者來確定是否執行。

[b][size=medium]2. 引數[/size][/b]

-name   filename             #查詢名為filename的檔案

-perm #按執行許可權來查詢

-user username #按檔案屬主來查詢

-group groupname #按組來查詢

-mtime -n +n #按檔案更改時間來查詢檔案,-n指n天以內,+n指n天以前

-atime -n +n #按檔案訪問時間來查

-ctime -n +n #按檔案建立時間來查詢檔案,-n指n天以內,+n指n天以前

-nogroup #查無有效屬組的檔案,即檔案的屬組在/etc/groups中不存在

-nouser #查無有效屬主的檔案,即檔案的屬主在/etc/passwd中不存

-newer f1 !f2 找檔案,-n指n天以內,+n指n天以前

-ctime -n +n #按檔案建立時間來查詢檔案,-n指n天以內,+n指n天以前

-nogroup #查無有效屬組的檔案,即檔案的屬組在/etc/groups中不存在

-nouser #查無有效屬主的檔案,即檔案的屬主在/etc/passwd中不存

-newer f1 !f2 #查更改時間比f1新但比f2舊的檔案

-type b/d/c/p/l/f #查是塊裝置、目錄、字元裝置、管道、符號鏈結、普通檔案

-size n[c] #查長度為n塊[或n位元組]的檔案

-depth #使查詢在進入子目錄前先行查詢完本目錄

-fstype #查更改時間比f1新但比f2舊的檔案

-type b/d/c/p/l/f #查是塊裝置、目錄、字元裝置、管道、符號鏈結、普通檔案

-size n[c] #查長度為n塊[或n位元組]的檔案

-depth #使查詢在進入子目錄前先行查詢完本目錄

-fstype #查位於某一型別檔案系統中的檔案,這些檔案系統型別通常可 在/etc/fstab中找到

-mount #查檔案時不跨越檔案系統mount點

-follow #如果遇到符號鏈結檔案,就跟蹤鏈結所指的檔案

-cpio #查位於某一型別檔案系統中的檔案,這些檔案系統型別通常可 在/etc/fstab中找到

-mount #查檔案時不跨越檔案系統mount點

-follow #如果遇到符號鏈結檔案,就跟蹤鏈結所指的檔案

-cpio #對匹配的檔案使用cpio命令,將他們備份到磁帶裝置中

-prune #忽略某個目錄

[b][size=medium]3. 例子[/size][/b]

find   -name april*                     #在當前目錄下查詢以april開始的檔案

find -name april* fprint file #在當前目錄下查詢以april開始的檔案,並把結果輸出到file中

find -name ap* -o -name may* #查詢以ap或may開頭的檔案

find /mnt -name tom.txt -ftype vfat #在/mnt下查詢名稱為tom.txt且檔案系統型別為vfat的檔案

find /mnt -name t.txt ! -ftype vfat #在/mnt下查詢名稱為tom.txt且檔案系統型別不為vfat的檔案

find /tmp -name wa* -type l #在/tmp下查詢名為wa開頭且型別為符號鏈結的檔案

find /home -mtime -2 #在/home下查最近兩天內改動過的檔案

find /home -atime -1 #查1天之內被訪問過的檔案

find /home -mmin +60 #在/home下查60分鐘前改動過的檔案

find /home -amin +30 #查最近30分鐘前被訪問過的檔案

find /home -newer tmp.txt #在/home下查更新時間比tmp.txt近的檔案或目錄

find /home -anewer tmp.txt #在/home下查訪問時間比tmp.txt近的檔案或目錄

find /home -used -2 #列出檔案或目錄被改動過之後,在2日內被訪問過的檔案或目錄

find /home -user cnscn #列出/home目錄內屬於使用者cnscn的檔案或目錄

find /home -uid +501 #列出/home目錄內使用者的識別碼大於501的檔案或目錄

find /home -group cnscn #列出/home內組為cnscn的檔案或目錄

find /home -gid 501 #列出/home內組id為501的檔案或目錄

find /home -nouser #列出/home內不屬於本地使用者的檔案或目錄

find /home -nogroup #列出/home內不屬於本地組的檔案或目錄

find /home -name tmp.txt -maxdepth 4 #列出/home內的tmp.txt 查時深度最多為3層

find /home -name tmp.txt -mindepth 3 #從第2層開始查

find /home -empty #查詢大小為0的檔案或空目錄

find /home -size +512k #查大於512k的檔案

find /home -size -512k #查小於512k的檔案

find /home -links +2 #查硬連線數大於2的檔案或目錄

find /home -perm 0700 #查許可權為700的檔案或目錄

find /tmp -name tmp.txt -exec cat {} \;

find /tmp -name tmp.txt -ok rm {} \;

find / -amin -10 # 查詢在系統中最後10分鐘訪問的檔案

find / -atime -2 # 查詢在系統中最後48小時訪問的檔案

find / -empty # 查詢在系統中為空的檔案或者資料夾

find / -group cat # 查詢在系統中屬於 groupcat的檔案

find / -mmin -5 # 查詢在系統中最後5分鐘裡修改過的檔案

find / -mtime -1 #查詢在系統中最後24小時裡修改過的檔案

find / -nouser #查詢在系統中屬於作廢使用者的檔案

find / -user fred #查詢在系統中屬於fred這個使用者的檔案

linux 檔案搜尋2 find

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 1.find命令處理動作 pr...

Linux運維 第二章 2 find命令詳解

find 作用 常在系統中作為查詢檔案所用到的角色 語法 find 查詢位置 查詢型別 查詢後所執行的操作 查詢位置 絕對路徑或相對路徑 查詢型別 name 根據檔名查詢 iname 不區分大小寫的方式查詢,只支援 等風格 perm 精確許可權查詢,後邊接許可權的掩碼值,掩碼值用法如下 755 查詢...

linux學習 find命令

用於在檔案樹中查詢檔案,並作出相應的處理 命令格式 find pathname options print exec ok 命令引數 pathname find命令所查詢的目錄路徑。例如用.來表示當前目錄,用 來表示系統根目錄。print find命令將匹配的檔案輸出到標準輸出。exec find命...