How to find files in Linux with the find command - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to find files in Linux with the find command
================================================

### [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [Finding files with find](#content-finding-files-with-find)
2. [Find by name](#content-find-by-name)
3. [Find by type](#content-find-by-type)
4. [Find by size](#content-find-by-size)
5. [Find by modification time](#content-find-by-modification-time)
6. [Searching a specific path](#content-searching-a-specific-path)
7. [Acting on results with -exec](#content-acting-on-results-with--exec)

[\#](#content-finding-files-with-find "Permalink")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  `, where the path is where to start searching.

[\#](#content-find-by-name "Permalink")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*'

```

[\#](#content-find-by-type "Permalink")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'

```

[\#](#content-find-by-size "Permalink")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.

[\#](#content-find-by-modification-time "Permalink")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.

[\#](#content-searching-a-specific-path "Permalink")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'

```

[\#](#content-acting-on-results-with--exec "Permalink")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](/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](/search-files-grep-command):

 ```
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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

- [Argument list too long (Bash: /bin/rm)](https://rocketeersapp.com/knowledge/argument-list-too-long)
- [How to install Composer packages locally](https://rocketeersapp.com/knowledge/install-composer-packages-locally)
- [How to send GET and POST requests with curl](https://rocketeersapp.com/knowledge/curl-post-get-api-requests)
- [Essential Linux command line basics for developers](https://rocketeersapp.com/knowledge/linux-command-line-basics)
- [How to search file contents with grep](https://rocketeersapp.com/knowledge/search-files-grep-command)
- [The complete guide to the curl command](https://rocketeersapp.com/knowledge/curl-command-complete-guide)

 [View all 21 articles →](https://rocketeersapp.com/knowledge/command-line)
