> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Find all files containing a given string
- URL: https://mfitzp.ghost.io/find-all-files-containing-a-given-string/
- Published: 2012-02-01T00:00:00.000Z
- Updated: 2023-06-26T08:36:33.000Z
- Author: Martin Fitzpatrick
- Tags: Bash, #Import 2024-03-14 08:20, #Import 2026-08-24 14:26

A quick one-liner to recursively search files for a given text string.

Open up a terminal session and enter the following - replacing `"foo"` with the text to search for.

```Bash
find . -exec grep -l "foo" {} \;

```

You can also limit the search to files with a particular extension (e.g. HTML or CSS). The first form will only return files in the current directory

```Bash
find *.html -exec grep -l "foo" {} \;

```

Alternatively you can search recursively while matching filenames using the `-name` parameter:

```Bash
find . -name *.html -exec grep -l "foo" {} \;

```

> *You can pass other options to find including for example `-mtime -1` to specify only files modified within the past day. You can also replace `.` with the name of any other folder to search:*

```Bash
find /var/www -name *.html -exec grep -l "foo" {} \;

```

This will search `/var/www` recursively for files named `*.html` and containing `foo`.