7

Let's say there a file called "abc_deh.xyz", what command do i use to find the location of that file in mac terminal by using solely the search term "deh"? So, basically, I am asking how to search for a file by text contained in its name. I need to find files that I forgot the whole name, that would be more helpful.

3 Answers 3

10
sudo find / -type f -name "*deh*"

if you want to search directories too then remove the -type f. You can also try: sudo locate deh

Should your locate database not be created (or up to date), there is a chance you have that file on the filesystem, but it's not been stored yet. Rather than run a single find command above, building the locate.db database might be a better plan going forward.

2

The mdfind command can be used to find all indexed files that contain a specific string in the filename.

In your case:

 mdfind -name deh
0

I use glob-complete-word a lot:

open */*deh # press \eg to complete paths

Also add set show-all-if-ambiguous on to ~/.inputrc if you haven't already. If there are multiple completions, it makes the first press of \eg show all of them. If it's not enabled and there are multiple paths that match */*deh, the *deh part is deleted.

If you use bash 4, shopt -s globstar makes ** match multiple levels of directories.

If you use mdfind or find and there is a single line of output, you can use a key binding like this to insert it:

"\eo": "$(!!)\e\C-e"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .