Using find



search and return results:



simple case sensitive search:


find <base_search_start_dir> -name <search_string>


simple case insensitive search:


find <base_search_start_dir> -iname <search_string>


simple search limiting by filetype(s):


find <base_search_start_dir> -type f -iname <search_string>


search multiple files using wildcards:


find <base_search_start_dir> -iname "*<search_string01>" -o -iname "*<search_string02>"


search files by access time (atime), modification time (mtime), or change time (ctime):


- this can be checked using stat command


- all three time options take argument ‘n’, where ‘n’ is number of days


‘-{a,c,m}time n’, where ‘n’ represents files modified between ‘n’ (incl) and ‘n+1’ (excl) days ago

‘-{a,c,m}time +n’, where ‘n’ represents files modified at least ‘n+1’ (incl) days ago

‘-{a,c,m}time -n’, where ‘n’ represents files modified less than ‘n’ (excl) days ago

find $HOME -mtime 0 find all files modified less than 24 hours

find $HOME -mtime +1 find all files modified 48 or more hours ago

find $HOME -mtime -1 find all files modified less than 24 hours ago



search and execute on results:



for files containing no spaces, tabs, or newlines


find <base_search_start_dir> -name <search_string> -exec <prog_to_exec> {} \;

‘{}’ is replaced with the resulting current filename

‘;’ is the delim for the command string following ‘-exec’

‘-exec’ can be replaced with ‘-ok’ if you want to verify each command


for files containing spaces, tabs, or newlines


find <base_search_start_dir> -name <search_string> -print0 | xargs -0 <prog_to_exec>

‘-print0’ prints full file name followed by null char

‘xargs’ replaces ‘-exec’
‘-0’ makes xargs treat input as null terminated



find tips:


Find recurses directories by default.  Best practice is to limit searches to known possible directories.