I am currently using Git Bash to navigate file directories and edit files. I want to know if there's a command to search the current directory and all directories in it for a file name.
-
1`git` and `bash` are two totally different things. `bash` is the Unix (or Linux) shell. `git` is a software source control program. As others have answered, there's a Unix/Linux command `find` which does what you want, and it's independent of `git` and works in any available shell, including `bash`. – lurker Jan 29 '14 at 17:47
5 Answers
Yes, it comes with the find utility. To recursively search for a file named "somefile.txt" starting from the current working directory, the following should work:
find . -name somefile.txt

- 81,402
- 15
- 141
- 199
-
1see answer by @misja111 comment if using windows: Use /bin/find not just find. – suh May 04 '18 at 20:14
-
1On git for Win 2.28.0 `$ find . -name "something"` does anyhow not work recursively. Can anybody confirm or clarify? – woodz Apr 01 '21 at 13:05
-
@woodz Your find might be pointing to the Windows version. See misja111's answer. – Giles Roberts Feb 01 '23 at 13:33
If you are using Git Bash on Windows, then it might well be that find
will point to the Find tool that comes with Windows and not to the one provided by Git Bash. The Windows Find tool searches for text within a file or files, similar to Unix's grep
.
You can verify by executing which find
. If it points to your Windows folder, it's not the Unix tool.
To be sure that you are using the Unix find
from the Git Bash shell, type /bin/find
. Now the -name
parameter will work as shown in other answers.
-
I'm using git for Windows and `find . -name somefile.txt` does work. For instance, I try `find . -name *.js` and it finds all .js files recursively. It took a while initially, because, I don't know, Windows? – Dave Heq May 09 '17 at 20:08
-
I had lots of trouble with a failing AppVeyor test that used `find` in the git bash. Thousand thanks for your answer! It saved my day. `bin/find` for the win! – Thomas Praxl Jan 11 '18 at 03:12
-
1
If you want to find e.g. all java file names containing the word 'Test', recursively from the current directory, you can use
git ls-files '*Test*.java'
To search for all files whose contents includes containing the word "FIXME", you can use
git grep 'FIXME'

- 116,971
- 11
- 170
- 194
Git Bash is a bash
shell underneath, and as such all standard Unix utilities will be available. The standard find
utility will work fine:
$ find . -name filename.java
will find filename.java
in your directory/subdirectories. Note that you have to escape wildcarding, otherwise the shell itself will interpret this e.g.
$ find . -name \*.java
will give you all the .java
files
find
is powerful, but can be complex to use. Check out a tutorial here.

- 268,207
- 37
- 334
- 440
-
Wow, this answer *completely* lost out to [the currently top-voted one](https://stackoverflow.com/a/21438636/95852) because it was apparently 15 seconds too slow. I gotta give this one an upvote (its first one?!) because it provides a useful superset of the information in that other answer. – John Y Mar 04 '22 at 16:29