find

walk a file hierarchy

Posted by kunnan on April 24, 2018

前言

SYNOPSIS

SYNOPSIS
     find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
     find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

man find

  • The options are as follows:
PRIMARIES
     All primaries which take a numeric argument allow the number to be preceded by a plus sign (``+'') or a minus sign (``-'').  A preceding plus sign means ``more than n'', a preceding minus sign means ``less than
     n'' and neither means ``exactly n''.
 -amin n
             True if the difference between the file last access time and the time find was started, rounded up to the next full minute, is n minutes.
 -mmin n
             True if the difference between the file last modification time and the time find was started, rounded up to the next full minute, is n minutes.
 -name pattern
             True if the last component of the pathname being examined matches pattern.  Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') may be used as part of pattern.  These characters
             may be matched explicitly by escaping them with a backslash (``\'').
 -size n[ckMGTP]
             True if the file's size, rounded up, in 512-byte blocks is n.  If n is followed by a c, then the primary is true if the file's size is n bytes (characters).  Similarly if n is followed by a scale indica-
             tor then the file's size is compared to n scaled as:

             k       kilobytes (1024 bytes)
             M       megabytes (1024 kilobytes)
             G       gigabytes (1024 megabytes)
             T       terabytes (1024 gigabytes)
             P       petabytes (1024 terabytes)             

EXAMPLES

按照文件特征查找

-size n[ckMGTP]
  • find / -size +10000c 
    查找出大于10000000字节的文件(c:字节,w:双字,k:KB,M:MB,G:GB)
    1) Taokeceshiji1:/var/mobile/Library/Preferences root# find / -size +100M
    2) find / -size -1000k   #查找出小于1000KB的文件 
    
-group gname
 True if the file belongs to the group gname.  If gname is numeric and there is no such group name, then gname is treated as a group ID.
  • Taokeceshiji1:/var/mobile/Library/Preferences root# find . -group mobile
属于 group为mobile 的文件 
-user uname
         True if the file belongs to the user uname.  If uname is numeric and there is no such user name, then uname is treated as a user ID.
  • Taokeceshiji1:/var/mobile/Library/Preferences root# find / -user mobile
查找在系统中属于 mobile 这个用户的文件 
-mmin n、-amin n: 查找在系统中最后n分钟里修改过的文件(modify time)、访问的文件
  • :~ root# find / -amin -1
  • Taokeceshiji1:/var/mobile/Library/Preferences root# find / -mmin -1
    这个命令我通常用来查看:当我按照一个deb 包之后,对系统修改的文件列表
    
-atime n[smhdw]
         If no units are specified, this primary evaluates to true if the difference between the file last access time and the time find was started, rounded up to the next full 24-hour period, is n 24-hour peri-
         ods.

         If units are specified, this primary evaluates to true if the difference between the file last access time and the time find was started is exactly n units.  Possible time units are as follows:

         s       second
         m       minute (60 seconds)
         h       hour (60 minutes)
         d       day (24 hours)
         w       week (7 days)

         Any number of units may be combined in one -atime argument, for example, ``-atime -1h30m''.  Units are probably only useful when used in conjunction with the + or - modifier.
  • find / -atime -2 
      # 查找在系统中最后48小时访问的文件
    
-empty
True if the current file or directory is empty.
  • :/var/mobile/Library/Preferences root# find / -empty
查找在系统中为空的文件或者文件夹

-name 按照文件名查找

  • find / ! -name “*.c” -print
               Print out a list of all the files whose names do not end in .c.
    
  • find /etc -name ‘srm
    使用通配符*(0或者任意多个)。表示在/etc目录下查找文件名中含有字符串‘srm’的文件
    

see also

  • SEE ALSO
    chflags(1), chmod(1), cvs(1), locate(1), lsvfs(1), whereis(1), which(1), xargs(1), stat(2), acl(3), fts(3), getgrent(3), getpwent(3), strmode(3), re_format(7), symlink(7)
    
/Users/devzkn/bin/knpost find walk a file hierarchy -t Terminal
#原来""的参数,需要自己加上""

转载请注明: > find