Knowledge

How to find files in Linux with the find command

#CommandLine

Locate files in Linux with the find command by name, type, size and modification time, and run actions on the results with -exec or -delete.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. Finding files with find
  2. Find by name
  3. Find by type
  4. Find by size
  5. Find by modification time
  6. Searching a specific path
  7. Acting on results with -exec

Finding files with find

When I need to track down a file and don't know exactly where it lives, find is the workhorse. It walks a directory tree recursively and matches files against the conditions you give it. The basic shape is find <path> <conditions>, where the path is where to start searching.

Find by name

Search by filename with -name. It matches the exact name, so use shell-style wildcards (quoted, so the shell doesn't expand them first):

find . -name '*.log'

If case shouldn't matter, use -iname instead. This matches README, readme and ReadMe:

find . -iname 'readme*'

Find by type

Limit results to files or directories with -type. Use f for regular files and d for directories:

find /var/www -type f -name '*.php'
find /var/www -type d -name 'cache'

Find by size

The -size flag matches on file size. Suffix the number with k, M or G, and prefix it with + for "larger than" or - for "smaller than":

find . -type f -size +100M

This finds files larger than 100 megabytes — handy for hunting down what's eating your disk.

Find by modification time

-mtime matches by how many days ago a file was last modified. -mtime -7 means changed within the last 7 days, while +30 means older than 30 days:

find /tmp -type f -mtime +30

For finer control, -mmin works the same way but in minutes.

Searching a specific path

The path argument can be anything — an absolute path, a relative one, or several at once:

find /etc /opt -name '*.conf'

Acting on results with -exec

Beyond listing matches, find can run a command on each one with -exec. The {} is replaced by the filename and \; ends the command:

find . -name '*.tmp' -type f -exec rm {} \;

For deleting specifically, the built-in -delete is cleaner and avoids the "argument list too long" error you'd hit with rm *:

find ./logs -name '*.log' -type f -delete

You can chain find with other tools too. To search the contents of every matching file, pipe the names into grep:

find . -name '*.php' -exec grep -l 'TODO' {} \;

Combine conditions freely — they're ANDed together — and find becomes a precise way to locate exactly the files you're after.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Argument list too long (Bash: /bin/rm)

Locate files in Linux with the find command by name, type, size and modification time, and run actions on the results with -exec or -delete.

Read more →

How to install Composer packages locally

Locate files in Linux with the find command by name, type, size and modification time, and run actions on the results with -exec or -delete.

Read more →