Search Files and Filenames

Two different questions, often confused:

  • Find a file by its name (or size, age, type) → find, fd, locate, rg --files.
  • Find a string inside files → grep, rg.

Each tool’s own flags live on its page; this hub frames the task and holds the methods that have no page of their own (find, fd, locate).

Find a file by name

find . -iname '*report*'                 # case-insensitive name match
find /path -type f -name '*.log'         # files only
find . -type d -name 'node_modules'      # directories only

By size or age:

find . -type f -size +100M               # larger than 100 MB
find . -type f -mtime -1                 # modified in the last day
find . -type f -newermt '2026-10-01'     # modified since a date

fd is a faster, friendlier alternative (the binary is called fdfind on Debian/Ubuntu):

fd report                # name contains "report"
fd -e md                 # by extension
fd -H -I secret          # include hidden and gitignored files

locate searches a prebuilt index, so it’s instant but only as fresh as the last index run:

locate -i report
sudo updatedb            # refresh the index

Find a string inside files

  • grep — available everywhere: grep -rniI --exclude-dir=.git 'pattern' .
  • ripgrep — faster, recursive by default: rg -i 'pattern'

Combine: search only files whose names match

find . -name '*.conf' -exec grep -Hn 'pattern' {} +
rg -g '*.conf' 'pattern'

List files that contain a string

grep -rl 'pattern' .
rg -l 'pattern'

Search inside archives and compressed files

Without unpacking them first — see Search Inside Archives.

On Windows

See Finding Strings in Files on Windows for a PowerShell version, or use rg, which runs natively on Windows.