I often use the Find command to look for filenames / directories which match some substring.
Note: Unlike grep, Find only looks at filenames. It doesn’t look at the contents of the files themselves.
 Find can be quite tricky when it comes to looking at substrings. Unlike grep, it doesnt look at substrings unless it is specified precisely using wildcards.
e.g. There is a difference between the two:
- find . -name ‘my*’
- This searches in the current directory (represented by the dot character) and below it, for files and directories with names starting with my
- find . -name ‘*my*’
- This searches in the current directory (represented by the dot character) and below it, for files and directories with names containing substring my.
 Find can be especially useful with the -exec option. Another possibility is to use xargs with find.
- However, I have come to the conclusion that its extremely risky to use either of these two with the find command . Read more here.
- Almost always there will be other ways to achieve the same thing. Do explore those before using the -exec option or before you use it with the xargs command.
 ignore case. By default find is case sensitive. However, recent versions of GNU
find have an
-iname flag, for case-insensitive name searches
$ find . -iname ‘*udo*’ -type d
 From current directory
find . -name ‘my*’
This searches in the current directory (represented by the dot character) and below it, for files and directories with names starting with my. The quotes avoid the shell expansion — without them the shell would replace my* with the list of files whose names begin with my in the current directory. In newer versions of the program, the directory may be omitted, and it will imply the current directory.
 Files only
find . -name ‘my*’ -type f
This limits the results of the above search to only regular files, therefore excluding directories, special files, pipes, symbolic links, etc. my* is enclosed in single quotes (apostrophes) as otherwise the shell would replace it with the list of files in the current directory starting with my……
 Search several directories
find local /tmp -name mydir -type d -print
This searches for directories named mydir in the local subdirectory of the current working directory and the /tmp directory.
- Useful Link: https://en.wikipedia.org/wiki/Find