Operations 7 min read

Mastering the Linux ‘find’ Command: Powerful File Search Techniques

Learn how to effectively locate files on POSIX systems using the versatile ‘find’ command, covering installation, name-based searches, wildcards, regular expressions, modification time filters, type restrictions, depth control, and practical examples for Linux, BSD, and macOS environments.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering the Linux ‘find’ Command: Powerful File Search Techniques

Installing find

The find utility is defined by the POSIX standard and is included by default on Linux, BSD, and macOS systems. Most distributions ship the GNU findutils package, which is widely used and easy to install.

Search by name

Use -name for case‑sensitive matches and -iname for case‑insensitive matches. Provide the directory to search and the pattern in quotes.

$ find ~ -name "foo"
/home/tux/Documents/examples/foo
$ find ~ -iname "foo"
/home/tux/Documents/examples/foo

Wildcards

Shell globbing can be used to broaden the search. * matches any number of characters, while ? matches a single character.

$ find ~ -iname "foo*"
/home/tux/Documents/examples/foo
/home/tux/Documents/examples/foo.xml
$ find ~ -iname "foo*.???"
/home/tux/Documents/examples/foo.xml

Regular expressions

The -regex and -iregex options apply a regular expression to the entire path, not just the filename. Use them when you need pattern matching across directory components.

$ find ~ -iregex ".*foo"
/home/tux/Documents/examples/foo

Finding recently modified files

Use -mtime with a negative number to find files modified within the last N days. Combine +N and -N to specify a range.

$ find ~ -mtime -7
# lists files changed in the last 7 days
$ find ~ -mtime +1 -mtime -7
# lists files changed more than 1 day ago but less than 7 days ago

Limiting by file type

The -type option filters results by file type. Common type letters are: d – directory f – regular file l – symbolic link s – socket p – FIFO (named pipe) b – block device

Examples:

$ find ~ -type d -name "Doc*"
/home/tux/Documents
$ find ~ -type f -name "Doc*"
/home/tux/Documents/DocExample.txt

Controlling search depth

By default find searches recursively. Use -maxdepth to limit how deep it descends and -mindepth to require a minimum depth.

$ find /usr -maxdepth 2 -iname "*xml"
# limits the search to two directory levels
$ find /usr -mindepth 8 -iname "*xml"
# starts reporting results only after eight levels

This quick reference demonstrates the most common find options for locating files efficiently on POSIX‑compatible systems.

Linuxshellcommand-linefindfile-search
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.