> For the complete documentation index, see [llms.txt](https://cp.rohanthe.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cp.rohanthe.dev/linux-essentials/finding-something.md).

# Finding Something

Using tools to find files, keywords in the Linux Filesystem

For using regular expressions with the following commands, checkout the [Regular Expressions Cheatsheet](/linux-essentials/regular-expressions-cheatsheet.md)

### GREP

> Find keywords inside files

**Finding Keywords inside files recursively and print the file names**

```bash
grep -rl "<keyword>" <path>
# grep -rl "service" /root
```

Using regular expression

Some other useful CLI options for grep

<table><thead><tr><th width="107.33333333333331">Flag</th><th width="421">Meaning</th></tr></thead><tbody><tr><td>-i</td><td>Ignore case</td></tr><tr><td>-c</td><td>Print count of matching lines</td></tr><tr><td>-v</td><td>Return all lines which don't match the pattern</td></tr></tbody></table>

### FIND

> Find files on the file system and maybe modify permissions (in bulk) if needed.&#x20;

```bash
#Syntax:
#find options starting/path expression

find / -name abc.txt 
```

#### Find files based on the time they were modified

> -mtime

```bash
find . -name abc.txt -mtime -7
#find abc.txt modified within the last 7 days
```

#### Find files recursively

> -maxdepth -> At max how many subdirectories should it traverse
>
> -mindepth -> Ignore the results before the depth specified.
>
> -mount -> Find files on this FS only.

```bash
find /mnt -name abc.txt -maxdepth 6 -mindepth 3 -mount
# Look for abc.txt within /mnt, ignore directories at depth 1 and 2; Look only
# in directories at level 3,4,5,6. Also, don't look at any other FS (ext4,efs,etc.) 
# mounted inside this path.
```

#### Set File Permissions in bulk

> -exec -> Execute shell commands

```bash
find . -type f -name "*.txt" -exec chmod 644 {} \;
find . -type d -exec chmod 750 {} \;
```
