cmd - find

最後更新: 2015-11-18

 

 


常用 Opts

 

time (-mtime)

Unit                  # n x 24 小時

+n                    # for greater than

-n                     # for less than n

n                      # n 當天 24 小時內的 file

i.e.

# n*24 hours ago

-mtime n

# file less than 24 hours ago

find $HOME -mtime 0

user

-uid n

-user <uname>

group

-gid n

-group gname

-iname          case  insensitive

 


Size

 

-size n[cwbkMG]

args

'b'    for 512-byte blocks

'c'    for bytes

'k'    for Kilobytes

'M'    for Megabytes

'G'    for Gigabytes

# 找出大過 10M 的信

-size +10M

 


Type

 

-type f | d | l

 


Permission

 

-perm

find . -perm 664         <-- permission 是 644

-664              <-- 最少有的意思 (This will match a file which has mode 0777)[without regard to the presence of any extra permission bits]

                           "All of the permission bits mode are set for the file."

/222              <-- Search for files which are writable by somebody

                           "Any of the permission bits mode are set for the file."

       find . -perm /220
       find . -perm /u+w,g+w
       find . -perm /u=w,g=w

# To find all SGID files:

find / -xdev -type f -perm +g=s -print

# To find all SUID files

find / -xdev -type f -perm +u=s -print

 


exec

 

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

應用 "-exec" 後

find . -type f -exec file '{}' \;

remark

'{}' 與 \; 之間要有空格

 


Looking for Files NOT owned by someone

 

find . \! -user foo -print

 


symbolic

 

-L     Follow symbolic links

 

# fine link file only

find . -maxdepth 1 -type l

 


Depth

 

-maxdepth levels

-mindepth levels