Back to course

29. Searching the System: The `find` Command (Basic)

Linux Basics: From Zero to CLI Hero

Locating Files by Attributes

The find command is one of the most powerful and complex commands. It traverses a directory hierarchy recursively, searching for files that match specified criteria.

Syntax

find [path] [expression]

Searching by Name

To search for files named config.txt starting in the current directory (.):

bash $ find . -name config.txt

Note: -name is case-sensitive. Use -iname for case-insensitive searching.

Searching the Entire System (Caution)

To search from the root (/), you might encounter 'Permission denied' errors, but the command will run.

bash $ find / -name '*.log'

Searches for all files ending in .log starting from the root.

Searching by Type (-type)

We often need to search only for directories (d) or regular files (f).

bash

Find all directories named 'data' under the current path:

$ find . -type d -name data