This section explains how to use the find command for file searches. In addition to file names, you can search for files using a variety of other criteria.
Format
find [search path] [options] [search expression]
Examples of Use
basis
( -name )
Search for the file Kernel.php in the current directory.
$ find . -name "Kernel.php"
./app/Http/Kernel.php
./app/Console/Kernel.php
case-sensitivity
( -iname )
Search for files in the current directory that contain the word controller (case insensitive).
$ find . -iname "*controller*"
Application with xargs
Delete files with the tmp extension in the current directory.
$ find . -name "*.tmp" | xargs rm -f
Conditional on the renewal date.
( -mtime )
Search for files in the current directory that have been updated within the last 3 hours.
find . -mtime -3h
Specify search hierarchy
( -maxdepth )
Search for files in the current directory (down to the second level) that have been modified within the last 3 days.
$ find . -maxdepth 2 -mtime -3
Directory only
( -type d )
Display only directories in the app directory (not lower level directories).
$ find app -maxdepth 0 -type d
File only
( -type f )
Show only files in app directory.
$ find app -type f
Subject to file permissions
( -perm )
Search for files with 777 permissions in the current directory.
$ find . -perm 777
Subject to file size
( -size )
Search for files larger than 10 MB in the current directory.
$ find . -size +10M
k
M
G
etc. can be specified.