簡介
find 是一個命令列工具,可以找尋特定名稱或條件的資料夾與檔案。
使用
使用 find 指令,找尋當前目錄下,檔案名稱為 hello.txt 的檔案。
1 | find . -name hello.txt |
找尋 src 目錄下,名稱為 hello.txt 的檔案。
1 | find src -name hello.txt |
使用 -iname 參數,不區分大小寫,找尋 src 目錄下,名稱為 hello.txt 的檔案。
1 | find src -iname hello.txt |
使用 -type d 參數,找尋名稱為 hello 的資料夾。
1 | find . -type d -name hello |
使用 -type f 參數,並搭配萬用字元,找尋副檔名為 php 的檔案。
1 | find . -type f -name "*.php" |
使用 -perm 參數,找尋權限是 777 的所有檔案。
1 | find . -type f -perm 0777 |
使用 -perm 參數,找尋權限不是 777 的所有檔案。
1 | find . -type f ! -perm 777 |
使用 -empty 參數,找尋空檔案。
1 | find . -type f -empty |
使用 -empty 參數,找尋空資料夾。
1 | find . -type d -empty |
使用 -user 參數,找尋 home 目錄下,root 使用者的所有檔案。
1 | find home -user root |