Linux學習筆記 find命令

2021-07-25 02:34:04 字數 2622 閱讀 3305

find 搜尋檔案系統 實時搜尋

find [目錄] [條件] [動作]

【目錄】

不輸入代表當前目錄

find

find /boot

[條件]

使用者和組 -user -group -nouser -nogroup

查詢/home 下擁有者為 mk 的檔案:

[root@localhost home]#find /home/ -user yang

[root@localhost home]#find /home/ -nouser yang

[root@localhost home]# find /home/ -group yang

[root@localhost home]#find /home/ -nogroupyang

【型別】 -type(f 檔案, d 目錄, l 連線, p 管道, c 字元檔案, b 塊檔案, s socket檔案)

[root@localhost home]# find /home/ -type d

[root@localhost home]#ll /dev/sda1

brw-rw---- 1 root disk 8, 1 dec  1 21:04 /dev/sda1

[root@localhost home]#find /dev/ -type b       #查詢塊檔案

【名字】 -name

[root@localhost home]#useradd user1

[root@localhost home]# find /home/ -name *user*

/home/user1

【大小】-size +nm 大於n兆 -ng 小於ngb

[root@localhost home]#find /boot/ -size -2g

【時間】 -mtime -atime -ctime

[root@localhost home]#find /tmp/ -mtime 1

-mtime +2  檢視不含今天的2天前被修改的所有檔案, 如:今天是 12月1日, 則找出3日及3日之前,被修改的內容

擴充套件:linux中 ctime, mtime, atime的區別

ctime : "改變時間(change time)"

mtime: "修改時間(modify time)"

atime : "訪問時間(access time)"

改變和修改之間的區別在於改檔案的屬性還是改檔案內容

ls(1) 命令可用來列出檔案的 atime, ctime 和 mtime

ls -lc filename   列出檔案的ctime

ls -lu filename  列出檔案的atime

ls -l filename    列出檔案的mtime

【許可權】 -perm

[root@localhost ~]# find /boot/ -perm 0755                #找到等於0755許可權的檔案或目錄

[root@localhost ~]# find /tmp -perm 1777              #sticky 1

[root@localhost ~]# find /tmp -perm 2777               #suid 2

[root@localhost ~]# find /tmp -perm 4777               #suid 4

[root@localhost ~]# find /tmp -perm  -777                #減號代表 至少有777許可權的檔案

【目錄深度】-maxdepth n #n 層次深度

[root@localhost ~]# find /boot -maxdepth 1

【多條件】

-a -o ! 或著 -and -or -not    與 或 非

在/root下找到其他人可以寫的檔案

[root@localhost ~]#find -type f -and -perm -002

./.ssh/id_rsa

./.ssh/id_rsa.pub

[root@localhost ~]#find -type f -and -perm /o+w

./.ssh/id_rsa

./.ssh/id_rsa.pub

其它人可以執行的非普通檔案的檔案

[root@localhost ~]#find ! -type f -and -perm -001

./.cache

./.cache/abrt

./.config

【動作】

-ls-ok

-exec

-print

-printf

[root@localhost ~]#find test2/ -type f -exec rm {} \;

引數解釋:

-exec    執行命令

rm  要執行的命令

{} 表示find -type f 查詢出來的檔案內容

\;              {}和\;之間要有空格 固定語法 就是以這個結尾

[root@localhost ~]#find test2/ -type f -exec dos2unix {} \;

linux學習 find命令

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

Linux學習筆記知識點 find命令

find命令會根據我們給的option,從給出目錄開始對其中檔案及子目錄下檔案進行遞迴搜尋,命令中尋找條件可以是單個,也可以是用邏輯運算子not,and,or 組成的復合條件。1 and 邏輯與,在命令中用 a 表示,是系統預設選項,表示所有條件都滿足 find name tmp type d us...

Linux學習之find命令

今天學習find命令 命令格式 find 路徑 引數 1 根據檔名使用正規表示式進行搜尋 find name txt iname 引數 忽略字母大小寫 2 多正則匹配進行檔案搜尋 find name txt o name log 上面命令會列印出所有的 txt 和 pdf 檔案 進行括號轉義 3 通...