I want to search for a file or folder in the directory I am viewing. I dont need to search recursively into sub-folders.
In Windows, if I am viewing a particular folder and want to search for files or folders that begin with the word "abc" then I type abc(not in the search box but I just type directly) and it highlights a file/folder. And then when I type "abc" again then it highlights the next file/folder that matches
Using Finder I see that only the first file/folder is highlighted. Even if I press escape and type again it only highlights the first matching file/folder. So I used the search box(command+F) to find all files/folders that begin with a particular word but this would search recursively i.e includes the sub-folders as well
I do not have files/folders sorted alphabetically in the directory that I am viewing
How can I do the search in this situation?
Best Answer
The
find
command in mac OS is quite expressive, despite the fact that Apple still ships a 2011 vintage.man find
will provide a list of all the arguments and options. There are some examples near the end of theman
page.N.B. this requires use of the Command Line Interface (CLI), so open/start/launch
Terminal.app
(it's located in theUtilities
folder inLaunchpad
). If you're mac OS version is Catalina, you'll be usingzsh
by default; otherwise your shell will bebash
. That's largely irrelevant to the answer here, but just so you know...I'll try to get you started based on some details in your question:
Use the
maxdepth
option to limit your recursion depth;-maxdepth 1
doesn't go below the specified folder. You can go deeper by increasingmaxdepth
beyond1
.Use the
-name
option (or a regular expression) to filter the results; in this case,-name "abc*", or if you wish the filter to be case-*insensitive* use
-iname "abc*".The
type
option allows you to filter your results by type; e.g. filter regular files withf
, or directories withd
. If you want files or directories, you may omit this option.Assuming the folder of interest is
/Users/YourName/YourData
, the command to use is as follows:Let us know if you have questions.
Some References:
BSD man page for
find
Know Your Tools: Linux (GNU) vs. Mac (BSD) Command Line Utilities