# command to find files

**URL:** <https://community.unix.com/t/command-to-find-files/286484>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [April 16, 2011, 10:44am UTC](https://community.unix.com/t/command-to-find-files/286484 "2011-04-16T10:44:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 16, 2011, 10:44am UTC](https://community.unix.com/t/command-to-find-files/286484/1 "2011-04-16T10:44:21Z")

</div>

Hi folks,

What command/commands I have to run to find the files including their folder/subfolder which contain word-a, word-b etc.

e.g. I expect to find the names of the files including their folders which contain "domain", "subdomain/sub domain", "free domain". etc.

TIA

B.R.  
satimis

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [April 16, 2011, 10:58am UTC](https://community.unix.com/t/command-to-find-files/286484/2 "2011-04-16T10:58:38Z")

</div>

```nohighlight
 ls -R | grep -E 'word-[ab]'

```

?

---

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 16, 2011, 11:06am UTC](https://community.unix.com/t/command-to-find-files/286484/3 "2011-04-16T11:06:55Z")

</div>

> [@ctsgnb](#):
>
> ```plaintext
> ls -R | grep -E 'word-[ab]'
> 
> ```
> 
> ?

Hi,

Whether run;

```plaintext
$ ls -R | grep -E 'domain subdomain sub domain free domain' /path/to/database

```

TIA

B.R.  
satimis

---

<div class="post-metadata">

**Author:** ![AlphaLexman](https://community.unix.com/user_avatar/community.unix.com/alphalexman/32/2160_2.png) [@AlphaLexman](https://community.unix.com/u/AlphaLexman)\
**Post date:** [April 16, 2011, 6:11pm UTC](https://community.unix.com/t/command-to-find-files/286484/4 "2011-04-16T18:11:20Z")

</div>

> [@satimis](#):
>
> I expect to find the names of the files including their folders which contain "domain", "subdomain/sub domain", "free domain". etc.

This should work,

```plaintext
find . -path "*domain*" 2> /dev/null

```

Will find files that do have 'domain' in the filename, and will find files that don't have 'domain' in the filename, but exist in a directory with 'domain' in the dirname.

You shouldn't need to search for `"subdomain/sub domain", "free domain". etc.` because the original search for 'domain' will find them all.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [April 17, 2011, 11:01am UTC](https://community.unix.com/t/command-to-find-files/286484/5 "2011-04-17T11:01:15Z")

</div>

In case the previous post is not right, my interpretation is:

```nohighlight
find . -name "*domain*" -print

```

---

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 17, 2011, 11:08am UTC](https://community.unix.com/t/command-to-find-files/286484/6 "2011-04-17T11:08:55Z")

</div>

> [@methyl](#):
>
> In case the previous post is not right, my interpretation is:
> 
> ```plaintext
> find . -name "*domain*" -print
> 
> ```

Hi,

I expect finding the files having "domain" in the content, not the filename. Thanks

B.R.  
satimis

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [April 17, 2011, 12:32pm UTC](https://community.unix.com/t/command-to-find-files/286484/7 "2011-04-17T12:32:56Z")

</div>

Really needs an example.

This is what I think you mean (find the names of files which contain the string "domain" in the content).

```nohighlight
find . -type f -exec grep -l "domain" {} \;

```

---

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 17, 2011, 10:01pm UTC](https://community.unix.com/t/command-to-find-files/286484/8 "2011-04-17T22:01:55Z")

</div>

> [@methyl](#):
>
> Really needs an example.
> 
> This is what I think you mean (find the names of files which contain the string "domain" in the content).
> 
> ```plaintext
> find . -type f -exec grep -l "domain" {} \;
> 
> ```

Hi,

I have files on /path/to/directories having contents on lists of websites offering free domain and subdomain. I also have files having contents about registration to some websites.

I tried

```plaintext
find /path/to/directories -type f -exec grep -l "domain" {} \;

```

I couldn't find them.

B.R.  
satimis

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 17, 2011, 10:33pm UTC](https://community.unix.com/t/command-to-find-files/286484/9 "2011-04-17T22:33:08Z")

</div>

Please post the exact command you typed, also, the contents of the file you expected to match.

it might also be a permissions problem. did you have permissions to look in these dirs?

---

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 17, 2011, 10:41pm UTC](https://community.unix.com/t/command-to-find-files/286484/10 "2011-04-17T22:41:36Z")

</div>

> [@corona688](#):
>
> Please post the exact command you typed, also, the contents of the file you expected to match.
> 
> it might also be a permissions problem. did you have permissions to look in these dirs?

$ find /home/satimis/Documents\_from\_2001\_2010/ -type f -exec grep -l "domain" {} \;

There are lot of files generated including .js/html/htm etc. Those files which I want to find are in .txt and .doc format. I think it would be better to narrow down the search. I have permission reading those directories. Besides I also tried the command with "sudo" added.

satimis

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 18, 2011, 12:41pm UTC](https://community.unix.com/t/command-to-find-files/286484/11 "2011-04-18T12:41:47Z")

</div>

> [@satimis](#):
>
> I think it would be better to narrow down the search.

Naturally. We couldn't help you with this until you actually told us.

```plaintext
find /home/satimis/Documents_from_2001_2010/ -type f '(' -name '*.txt' -o -name '*.doc' ')' -exec grep -l "domain" {} \;

```

> [@](#):
>
> Besides I also tried the command with "sudo" added.

added where?

Also:

> [@corona688](#):
>
> Please post the exact command you typed, also, the contents of the file you expected to match.

There may be a reason it's not matching.

---

<div class="post-metadata">

**Author:** ![satimis](https://community.unix.com/letter_avatar/satimis/32/5_5575768a8748004e209b776fc1b2916d.png) [@satimis](https://community.unix.com/u/satimis)\
**Post date:** [April 18, 2011, 11:06pm UTC](https://community.unix.com/t/command-to-find-files/286484/12 "2011-04-18T23:06:32Z")

</div>

Hi,

Thanks for your assistance.

> [@corona688](#):
>
> ```plaintext
> find /home/satimis/Documents_from_2001_2010/ -type f '(' -name '*.txt' -o -name '*.doc' ')' -exec grep -l "domain" {} \;
> 
> ```

The command works. However it generates lot of files.

Years ago, I registered several subdomains with some websites. Because of inactive I suppos they have been deleted. I need to re-register them. Unfortunately I can't recall those websites nor the name of the company. What I can remember is all subdomain starting with "satimis" e.g. [satimis.aaa.com](http://satimis.aaa.com) or [satimis.bbb.net](http://satimis.bbb.net) or [satimis.ccc.org](http://satimis.ccc.org) etc. If I expect to narrow down the searching please advise what shall I add to your command. Thanks

> [@](#):
>
> added where?

At the beginning of your command. Because some files may be owned by root.

B.R.  
satimis
