天天看點

shell程式設計——find檔案查找入門

find簡單介紹

find指令用來搜尋指定檔案

搜尋到指定檔案後可執行某些動作,例如rm操作

檔案準備

mkdir /tmp/jackin; cd /tmp/jackin

for line in $(seq 10);do

  touch file_$line

  mkdir dir_$line

done

ln -s /tmp/jackin/file_10 /tmp/jackin/file_link

touch -d "365 days ago" file_9

chown nobody:nobody file_8

find文法

find 目錄 選項 動作

find選項說明

選項可按檔案類型、更改時間、名字等進行查找

無選項預設全查找

find動作說明

動作預設print,輸出查找到的檔案路徑

動作可以自定義

根據檔案類型查找-type

f 普通檔案 file

d 目錄 directory

l 連結檔案

b 塊裝置檔案

c 字元裝置檔案

p 管道檔案

find /tmp/jackin -type f

find /tmp/jackin -type l

find根據檔案名字查找

find /tmp/jackin -name "file_9" #隻支援通配符

根據檔案的使用者、使用者組來查找

find /tmp/jackin -type f -user nobody

find /tmp/jackin -type f -group nobody

find反向查找

find /tmp/jackin/ -type f ! -user nobody

find指令幫助

find --help

繼續閱讀