LinuxTutorial2 min read

How to Find Files on Linux

Use find, locate, which, and whereis to track down any file on your Linux system quickly — from searching by name to filtering by size and date.

Developer terminal on a laptop in low light

Four Ways to Find Files on Linux

Linux gives you several tools for finding files, each suited to a different use case. find is the most powerful; locate is the fastest for simple name searches; which and whereis locate programs and their documentation.

find — The Most Powerful Option

find searches the live file system in real time. Basic syntax: find [directory] [options]

Search by name

find /home -name "report.txt"           # exact match
find /home -name "*.log"                # all .log files
find /home -iname "*.PDF"               # case-insensitive

Search by type

find /var -type f -name "*.conf"        # files only
find /var -type d -name "cache"         # directories only

Search by size

find / -size +100M                      # files larger than 100 MB
find /tmp -size -1k                     # files smaller than 1 KB

Search by modification time

find /home -mtime -7                    # modified in last 7 days
find /var/log -mtime +30                # not modified in 30+ days

Execute a command on results

find /tmp -name "*.tmp" -delete         # delete all .tmp files
find . -name "*.log" -exec gzip {} ;   # gzip each found file

locate — Blazing Fast Name Search

locate searches a pre-built database, so it's much faster than find but may be slightly out of date.

locate nginx.conf
sudo updatedb                           # refresh the database

Install it if missing: sudo apt install mlocate

which — Find Where a Program Lives

which python3
# /usr/bin/python3

which git
# /usr/bin/git

which searches only the directories in your $PATH and returns the first match.

whereis — Find Program, Source, and Manpage

whereis nginx
# nginx: /usr/sbin/nginx /etc/nginx /usr/share/man/man8/nginx.8.gz

whereis returns the binary, source files, and man page locations in one shot.

Practical Tip: Suppress Permission Errors

When running find across the whole filesystem, you'll see many "Permission denied" errors. Suppress them by redirecting stderr:

find / -name "*.conf" 2>/dev/null