find 命令

  1. 功能強大的檔案搜尋指令 find
    [root@kvm8 ~]# find --help
    Usage: find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]
    
    Default path is the current directory; default expression is -print.
    Expression may consist of: operators, options, tests, and actions.
    
    Operators (decreasing precedence; -and is implicit where no others are given):
          ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2
          EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2
    
    Positional options (always true):
          -daystart -follow -nowarn -regextype -warn
    
    Normal options (always true, specified before other expressions):
          -depth -files0-from FILE -maxdepth LEVELS -mindepth LEVELS
          -mount -noleaf -xautofs -xdev -ignore_readdir_race -noignore_readdir_race
    
    Tests (N can be +N or -N or N):
          -amin N -anewer FILE -atime N -cmin N -cnewer FILE -context CONTEXT
          -ctime N -empty -false -fstype TYPE -gid N -group NAME -ilname PATTERN
          -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
          -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
          -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
          -readable -writable -executable
          -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
          -used N -user NAME -xtype [bcdpfls]
    
    Actions:
          -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
          -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
          -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
          -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;
    
    Other common options:
          --help                   display this help and exit
          --version                output version information and exit
    
    Valid arguments for -D:
    exec, opt, rates, search, stat, time, tree, all, help
    Use '-D help' for a description of the options, or see find(1)
    
    Please see also the documentation at https://www.gnu.org/software/findutils/.
    You can report (and track progress on fixing) bugs in the "find"
    program via the GNU findutils bug-reporting page at
    https://savannah.gnu.org/bugs/?group=findutils or, if
    you have no web access, by sending email to <bug-findutils@gnu.org>.
    
    參數:
    1. 與時間有關的參數:
       -atime n :在 n 天之前的『一天之內』被 access 過的檔案;
       -ctime n :在 n 天之前的『一天之內』被 change 過狀態的檔案;
       -mtime n :在 n 天之前的『一天之內』被 modification 過的檔案;
       -newer file :比檔案 file 還新的檔案。
    2. 與使用者或群組名稱有關的參數:
       -uid n :使用者的帳號 ID,UID=n 的檔案
       -gid n :群組名稱的 ID,GID=n 的檔案
       -user name :使用者帳號名稱為 name 的檔案
       -group name:群組名稱為 name 的檔案
       -nouser    :檔案的擁有者不存在的檔案
       -nogroup   :檔案的擁有群組不存在的檔案
    3. 與檔案權限及名稱有關的參數:
       -name filename:檔案名稱為 filename 的檔案;
       -size [+-]SIZE:比 SIZE 還要大(+)或小(-)的檔案。SIZE 的規格有:
                       c:byte, k:1024bytes M:1048576bytes。例如:-size +50k。
       -type TYPE    :檔案的類型為 TYPE 的檔案,類型主要有:一般正規檔案 (f),
                       裝置檔案 (b, c), 目錄 (d), 連結檔 (l), socket (s), 
                       及 FIFO (p) 等屬性。
       -perm mode  :檔案屬性『剛好等於』 mode 的檔案
       -perm -mode :檔案屬性『必須包含所有 mode 的屬性』的檔案,權限數值大於等於 mode。
       -perm +mode :已不支援。
    4. 額外可進行的動作:
       -exec command {} \; :-exec 後再接指令 command 來處理搜尋的結果,
                             {} 為找到的內容,
                             分號 ; 為命令的結束符號,但要用反斜線 \ 跳脫。
       -print        :將結果列印到螢幕上(預設動作)