Could you clarify whether you're searching for a file name matching a pattern or a string contained in a file? You mentioned both
find and
grep and usually
find is best suited for locating files whereas
grep is best suited for locating strings within files.
If you're just looking for a file, my preferred way is through the
mlocate program; the usage is to run
sudo updatedb to update the mlocate database and run
locate pattern to find files matching
pattern; you can also use regular expressions here -- consult the manual with
man locate for details. Alternatively, you can use the
find command with syntax like:
Code:
find /path/to/top/directory/ -type f -name '*pattern*'
which matches files with
pattern in their name recursively starting at
/path/to/top/directory/. Alternatively you can use
Code:
find /path/to/top/directory/ -type f -regex 'regularExpressionGoesHere'
if regex is more suitable. You can also use
-type d to only find directories.
If you're looking for a string within a file you definitely want to be using
grep. Sample syntax might be:
Code:
grep -ir 'regularExpressionGoesHere' /path/to/top/directory/
where the options
-i make the pattern case insensitive and
r makes the search recursive.
If you need clarification let me know.