The find command without any options will list the files at and below the present working directory.
~]# find . ./.bash_logout ./.bash_profile ./.bashrc ./.bash_history ./file1
By default, the the find command will search for files at and below the present working directory. To search at and below a certain directory, include the directory to search in the find command. In this example, the find command will search for files at and below the /home directory.
~]# find /home . ./.bash_logout ./.bash_profile ./.bashrc ./.bash_history ./file1
lf you want to search for multiple specific files or directories, you simply just specify each file or directory to search.
~]# find /path/to/directory1 /path/to/directory2
The maxdepth and mindepth options can be used to only display the files in the search directory, and to exclude the parent and child directories.
find /path/to/directory -maxdepth 1 -mindepth 1
The -name option can be used to only show results matching name. In this example, only results matching "file2" will be displayed. The -name option is CaSe SenSiTiVe.
~]# find / -name file2 /home/jane.doe/file2
The -iname option can be used to ignore case. In this example, both file2 and File2 are found.
~]# find / -iname file2 /home/jane.doe/file2 /home/jack.doe/File2
If you do not know the full file name you are searching for, you can use double quotes and wild cards.
~]# find / -iname "*ammple*" /home/jane.doe/Downloads/Sample2
Or to return results for multiple files or directories.
find / -iname foo -o -iname bar
An exclamation point can be used to find files that do not match a certain pattern. In this example, files that are not named "example" will be returned.
~]# find / ! -name "example"
Often, you know that you are searching for a file or a directory, not both. The -type f option can be used to only find files and the -type d option is used to or only find directories. In this example, find searches for directories named bin.
~]# find / -name bin -type d /usr/bin /usr/lib/debug/usr/bin /usr/share/locale/bin /usr/local/bin
The -type option can accept the following values:
Following are additional popular things you can do with the find command.