find

Basic command overview:

To search for files within a directory hierarchy

$ find <start_directory> [flags]

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

-path

The -pathflag allows matching of forward slash characters (/). This can allow searching within sub-directories of folders

The asterisk (*) in the search pattern for -name and -path flags are used for wildcard matching. To illustrate ...

Difference between -name and -path

-type

To search by file type ...

-perm

To search files by permissions ...

owner-group-users -> rwxrwxrwx -> 111 111 111 -> 777 (?)

excerpt from https://man7.org/linux/man-pages/man1/find.1.html

Last updated