> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Find a File by Name and Search Text on Linux

> Find a file by name on Linux with find / -name 'file.conf' and search text inside files with grep -rn 'text' /path. Includes locate, size and date filters.

To find a file by name on Linux, run `sudo find / -name "nginx.conf" 2>/dev/null`; use `-iname` to ignore upper and lower case and `*` as a wildcard, for example `-name "*.log"`. To search for text inside files, run `grep -rn "server_name" /etc/nginx`: `-r` searches all subfolders and `-n` shows the line number of every match.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Every Linux distribution | sudo to search system folders |

## Before you start

* [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md).
* Searching the whole disk from `/` can take a while and shows many "Permission denied" lines without `sudo`. Use `sudo` (root can leave it out), start in the most likely folder, and add `2>/dev/null` to hide error messages.

## How to find a file by name

```bash theme={null}
find /etc -name "sshd_config"
```

Expected output:

```text theme={null}
/etc/ssh/sshd_config
```

| Goal | Command |
| - | - |
| Exact name, whole server | `sudo find / -name "wp-config.php" 2>/dev/null` |
| Ignore case | `find /var/www -iname "readme.md"` |
| All files with an extension | `find /var/log -name "*.log"` |
| Only files / only folders | `find /srv -type f -name "*.yml"` / `find /srv -type d -name "backups"` |
| Stay on one disk | `sudo find / -xdev -name "*.sql"` |

Always put the name in quotes when it contains `*`, so the shell doesn't expand it first.

## How to find files by size or date

```bash theme={null}
sudo find / -xdev -type f -size +1G 2>/dev/null        # larger than 1 GB
find /var/www -type f -mtime -1                       # changed in the last 24 hours
find /tmp -type f -mtime +7                           # older than 7 days
find /home/alex -type f -newer /home/alex/marker.txt  # newer than another file
sudo find /var/www -user www-data -perm -o+w          # files anyone can write to
```

`-mtime -1` means "less than one day ago"; `+7` means "more than seven days ago". `-mmin -30` works in minutes.

### How to act on the files you find

Show details:

```bash theme={null}
find /var/log -name "*.gz" -exec ls -lh {} +
```

Delete old files:

```bash theme={null}
find /home/alex/backups -name "*.tar.gz" -mtime +30 -print
find /home/alex/backups -name "*.tar.gz" -mtime +30 -delete
```

> [!WARNING]
>
> `-delete` removes files permanently with no confirmation. Run the same command with `-print` first, read the list, then replace `-print` with `-delete`. Never run a `-delete` search from `/`.

## How to find a file quickly with locate

`locate` searches a prebuilt index, so it answers instantly.

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt install plocate
> sudo updatedb
> locate sshd_config
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf install mlocate
> sudo updatedb
> locate sshd_config
> ```
>
> On AlmaLinux and Rocky 10 the package is `plocate`.

The index is refreshed once a day, so brand-new files only appear after `sudo updatedb`.

## How to search for text inside files with grep

```bash theme={null}
grep -rn "server_name" /etc/nginx
```

Example output:

```text theme={null}
/etc/nginx/sites-available/example.com:4:    server_name example.com www.example.com;
```

Each line shows the file, line number and matching text.

| Option | Effect | Example |
| - | - | - |
| `-r` | Search all subfolders | `grep -r "DB_HOST" /var/www` |
| `-n` | Show line numbers | `grep -n "Port" /etc/ssh/sshd_config` |
| `-i` | Ignore case | `grep -ri "error" /var/log/nginx` |
| `-l` | Only list file names | `grep -rl "example.com" /etc` |
| `-w` | Whole words only | `grep -w "root" /etc/passwd` |
| `-v` | Lines that do **not** match | `grep -v "^#" /etc/ssh/sshd_config` |
| `-E` | Extended regex, e.g. "this or that" | `grep -E "error\|warn" app.log` |
| `--include` | Only some file types | `grep -rn --include="*.php" "mysqli_connect" /var/www` |
| `-C 3` | Show 3 lines around each match | `grep -C 3 "Out of memory" /var/log/syslog` |

To see a config file without comments and blank lines:

```bash theme={null}
grep -Ev "^\s*(#|$)" /etc/ssh/sshd_config
```

### Search command output

Pipe any command into `grep`:

```bash theme={null}
ps aux | grep nginx
sudo ss -tulpn | grep ":443"
```

## How to check it worked

Create a test file and find it both ways:

```bash theme={null}
echo "hello from alex" > ~/findme.txt
find ~ -name "findme.txt"
grep -rn "hello from" ~
```

Both commands print `/home/alex/findme.txt`; grep adds `:1:hello from alex`.

## Frequently asked questions

### How do I find which config file sets a value?

Search the config folder for the setting name: `sudo grep -rn "upload_max_filesize" /etc/php`. The last file loaded usually wins.

### Is there a faster grep?

`ripgrep` (`rg`) skips binary and ignored files and is much faster on large trees. Install it with `sudo apt install ripgrep` on Ubuntu/Debian; on AlmaLinux/Rocky it is in EPEL.

### How do I find which package owns a file?

Use `dpkg -S /usr/sbin/nginx` on Ubuntu/Debian and `rpm -qf /usr/sbin/nginx` on AlmaLinux/Rocky.

### How do I find where a command is installed?

Run `command -v nginx` or `which nginx`. `type -a nginx` shows every match on your `PATH`.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Essential Linux commands](https://help.freakhosting.com/portals/other/essential-linux-commands-for-server-beginners.md)
>
> The commands you use every day.

> [card] [Check disk space](https://help.freakhosting.com/portals/other/how-to-check-disk-space-on-linux.md)
>
> df and du explained.

> [card] [Read logs with journalctl](https://help.freakhosting.com/portals/other/how-to-read-logs-with-journalctl.md)
>
> Search the systemd journal.

***

> [!NOTE]
>
> **Checked against the official [GNU findutils manual](https://www.gnu.org/software/findutils/manual/html_mono/find.html) and [GNU grep manual](https://www.gnu.org/software/grep/manual/grep.html)** on 4 November 2026; commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.