Find

Find.

Introduction

 * find is significally slower than locate but more reliable
 * locate need file database to be up-to-date (by updatedb command)

Syntax
find [-H|-L|-P] [path] [options] [expression]
 * -P: ignore symlinks
 * -L: follow symlinks
 * -H: ignore symlinks except given path is a symlink

Options

 * -amin n, -atime n: Finds the file last accessed n minutes ago, or n × 24 hours ago.
 * -cmin n, -ctime n: Finds the file status last changed n minutes ago, or n × 24 hours ago.
 * -mmin n, -mtime n: Finds the file last modified n minutes ago, or n × 24 hours ago.
 * -mount: ignore directories on other filesystems


 * -iname: like -name but case insensitive
 * -regexp: whole path matches the regex
 * -type filetype, -size m, -user username, -group groupname (￼filetype: Regular file f, Symbolic link l, Directory d, Character special device c, Block device b, Socket s, FIFO p)
 * -maxdepth/-mindepth: base on the directory depth
 * -print/-print0: ('\n' or '\0' as the delimiting character). Usually -print0 goes with -0 option of xargs.

Examples
Match file name find ./logall -type f -mtime +30 (old files, days) find. -name "*.mp3" -size 0 -print Multiple criteria find. \( -name "*.txt" -o -name "*.pdf" \) -print Match a path find /home/users -path "*/slynux/*" -print Regex find. -regex ".*\(\.py\|\.sh\)$" find. -iregex ".*\(\.py\|\.sh\)$" Time reference find. -type f -newer file.txt -print Size find. -type f -size +2k (+/-, b/c/w/k/M/G) Negating argument find. ! -name "*.txt" -print

Skip specific directories
Use -prune to skip specfic directories find dir \( -name ".git" -prune \) -o \( -type f -print\)