Finding Files
Created Sunday 06 December 2009

2 main options: FIND and LOCATE

GENERAL NOTES:
-asterisks for wildcards
-can put quotes around pattern if contains spaces

The LOCATE command is the simplest and fastest. It searches the whole filesystem for filenames/directories CONTAINING pattern (i.e. it searches with wildcards: *pattern*)
locate [options] pattern

NOTABLE OPTIONS
-b ~ match the pattern against the basename of files/dirs instead of their whole paths - I ALWAYS do this.
(if this is not set and you search for 'music', then you will get a result for every file in your music directory, as all of those files have 'music' in their paths!)
-i ~ ignore case
-c ~ only output the count

EXAMPLES
locate -b -i jack ~ find all files/dirs CONTAINING the (case-insensitive) word jack i.e. search for *jack*
locate -b dump ~ find all files/dirs CONTAINING the pattern 'dump' (i.e. this will match a file with the name test_dump7.sql)
locate -b '\dump.sql' ~ find all files/dirs with the EXACT name dump.sql (the backslash tells locate NOT to auto-add wildcards, though you can still add them manually)

BUT: the speed comes at a price: the locate command is only searching a database, which is only updated by running the command:
sudo updatedb
(this is automatically run at set intervals, maybe nightly?)

The FIND command is more flexible, and actually does a live search (can be much slower). It recursively searches for pattern in dir (default to current dir)
find [dir] [options] pattern

NOTABLE OPTIONS
-maxdepth 5 ~ limit the depth of the recursive search to 5 levels
-iname ~ ignore case

EXAMPLES
find films/ -iname *idaho* ~ recursively search through my films directory to find all files containing the word idaho
find -maxdepth 1 -iname *.cpp ~ check THIS directory (and no sub-directories) for cpp files

Name
Email (Required, not published)
Website