To search from the current directory, use a period . as the start directory
$ find . [flags]
To search from the root directory (/)
$ find / [flags]
# eg.
$ find / -name flag.txt
Permission denied error message
Sometimes there may be an error message returned similar to the following:
find: ‘/...’: Permission denied
Simply append 2>/dev/null at the end of the command:
# 2>/dev/null redirects all errors to /dev/null. This essentially
# flushes all the errors away
$ find ... 2>/dev/null
Useful flags
-name
To find by base of filename, with the leading directories removed. The -path flag discussed below can be used instead if leading directories searches are required
Searching files by permissions
• Search for files which are executable but not readable.
$ find /sbin /usr/sbin -executable \! -readable -print
• Search for files which have read and write permission for
their owner, and group, but which other users can read but
not write to.
$ find . -perm 664
Files which meet these criteria but have other permissions
bits set (for example if someone can execute the file)
will not be matched.
• Search for files which have read and write permission for
their owner and group, and which other users can read,
without regard to the presence of any extra permission
bits (for example the executable bit).
$ find . -perm -664
This will match a file which has mode 0777, for example.