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.
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
$ find . -name "something"
does anyhow not work recursively. Can anybody confirm or clarify? –
Calesta 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.
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? –
Olivares find
in the git bash. Thousand thanks for your answer! It saved my day. bin/find
for the win! –
Phenyl which find
on Git Bash gives me /usr/bin/find
instead. –
Etan 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'
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.
You can simply run this command on the git shell:
find / -name 'filename-you-want-search-regex-allowed'
This will search all the files below /
across file system.
© 2022 - 2024 — McMap. All rights reserved.
git
andbash
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 commandfind
which does what you want, and it's independent ofgit
and works in any available shell, includingbash
. – Backscratcher