47

I am in a directory which contains more directories. What command can I use to get all files ending with .rb?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
balaji
  • 1,075
  • 3
  • 12
  • 26

4 Answers4

82

You could try

find . -type f -name \*.rb
Emmanuel
  • 16,791
  • 6
  • 48
  • 74
bmk
  • 13,849
  • 5
  • 37
  • 46
  • What's the difference from `find . -type f -name *.rb`? – pmor Aug 31 '23 at 14:33
  • 1
    If 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
  • 2
    wouldn'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
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