1

I am working on the Linux terminal and I want to know how to search for c files in a certain directory. I have it working for the current directory but how do I do it for the directory usr/

for the current directory i did

grep -l "main" *.c

so I'd like to know how to search in the /usr directory without changing the directory first. Thanks.

2 Answers 2

4

You should just be able to prefix the directory name you want to the file pattern you want to search.

grep -l "main" /usr/*.c
0

You could also use:

find /usr/ -name "*.c"

if it is just the C files in the /usr/ directory you are after.

Not the answer you're looking for? Browse other questions tagged or ask your own question.