Find Files in Linux with find and locate

Linux has two common ways to search for files: find, which searches the filesystem directly, and locate, which searches a prebuilt filename database.

Use find for current results

find /path -name 'filename'
find /path -iname '*.log'

find reflects the current filesystem state and supports filters for type, size, owner, modification time, permissions, and more.

Use locate for fast filename searches

locate filename
locate -n 20 filename

locate is fast because it searches an index. If a new file does not appear, refresh the database with the distribution’s updatedb command, usually with administrative privileges.

Use find when correctness and current state matter; use locate when you want a quick filename lookup across the system.

Leave a Comment