I am in a directory which contains more directories.
What command can I use to get all files ending with .rb
?
Asked
Active
Viewed 8.8k times
47

Martin Thoma
- 124,992
- 159
- 614
- 958

balaji
- 1,075
- 3
- 12
- 26
-
3For future reference, these types of questions belong here: http://unix.stackexchange.com/ – jonescb Mar 21 '11 at 15:15
4 Answers
82
-
-
1If you don't escape the ’*’ the shell will try to match the pattern and doesn't pass it to 'find'. Therefore this will only work If the files reside within the current working directory. – bmk Sep 01 '23 at 15:17
14
Try this find . -type f -name '*.rb'
.
For a more thorough explanation, get the 'Unix Power Tools' book.

Victor Sorokin
- 11,878
- 2
- 35
- 51
-
2wouldn't that also find files without a dot in front of the `rb`? The OP was very specific, so I think your answer should be too :) – 0xC0000022L Mar 21 '11 at 13:17
5
This should help:
find . | grep *\.rb

pechenie
- 1,908
- 2
- 18
- 17
-
Sorry, overlooked. Reverted. I was taken aback by using 'pipe grep' in case when all needed functionality already built-in inside `find`. – Victor Sorokin Mar 21 '11 at 11:49
-
1
0
You can find all the files ending with .rb by following command
find . -type f -name '*.rb'
To store the results after finding, you can use the following command
filesEndingWithRb=$(find . -type f -name '*.rb')
To print the results
echo $filesEndingWithRb

Akshay Chopra
- 1,035
- 14
- 10