239

I want to search for all .conf files in /etc/.

I tried grep -r *.conf /etc, but the result isn't right.

What am I doing wrong?

Adrian George
  • 3,671
  • 8
  • 24
  • 30

5 Answers5

368

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below:

find . -type f -name "*.txt"

This will list all files with the extension .txt.

The . at the start denotes the current directory. find searches recursively in all the directories below the given path. If you want the search to start somewhere other than the current working directory, specify the path, for example:

find /etc -type f -name "*.conf"

This searches the /etc directory and all its subdirectories for regular files with the .conf extension.

Zanna
  • 72,312
Mitch
  • 109,787
12

grep searches the contents of files, not the file names.

To find all .conf files in /etc/ you'll want find:

find /etc -name "*.conf"
Zanna
  • 72,312
10

I'd personally use find, but you can glob for these things too:

shopt -s globstar
ls /etc/{,**/}*.conf

And you can use locate and it's fast but not reliable.

locate '/etc/**.conf'
Oli
  • 299,380
4

How about using a simple ls command:

ls /etc/*.conf

This uses glob pattern (File name expansion), so it only finds files in immediate directory and not subfolders

hiru007
  • 45
Ivan
  • 141
0

The following command will return all files and folders ending in .conf:

ls -lR /etc | grep ".conf$"

To find only files, run:

find /etc -type f -name '*.conf'
ggorlen
  • 115
nibble
  • 11