1.6 Search for files

There may be times when you know a file or directory exists but you do not know where to find it. There are several commands you can use to search for it, including find, locate, and which.

CentOS 7

The find command has many options that you can review in man page. The most common option is -name, which tells find to search for all files and directories with a certain string of letters in their name.

# find / -name ping6

With locate, you can see every file or directory whose name contains the search criterion. The locate command uses a database to locate files and directories that have the word "pattern" in the file or directory name. The search results could include a file called pattern.txt, a file called pointerpattern.txt, a directory named /patternthumbnails/, and so on. To learn more about locate, read the locate man page.

The locate command works very quickly, as long as the database is up to date. That database is automatically updated on a nightly basis through a cron job.

For example, to search for all files with the word ping6 in the name, type:

# locate ping6

The which returns the location of binary, or executable, shell commands.

# which ping6

The following command returns the locations of: the binary of ping6, the location of the source code, and the location of the find man page.

# whereis ping6
ping6: /usr/bin/ping6 /usr/sbin/ping6 /usr/share/man/man8/ping6.8.gz

The whatis command return information about the command from its man page.

# whatis ping6
ping6 (8)            - send ICMP ECHO_REQUEST to network hosts

openSUSE Leap 42.3

The same way as in CentOS 7

Ubuntu 17.04

The same way as in CentOS 7

Publication/Release Date: Jun 26, 2017
Reviewed: Jun 28, 2017