Search for files that begin with some letters and the search need to be non-recursive

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?


Solution 1:

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 the man page.

N.B. this requires use of the Command Line Interface (CLI), so open/start/launch Terminal.app (it's located in the Utilities folder in Launchpad). If you're mac OS version is Catalina, you'll be using zsh by default; otherwise your shell will be bash. 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:

I don't need to search recursively into sub-folders.

Use the maxdepth option to limit your recursion depth; -maxdepth 1 doesn't go below the specified folder. You can go deeper by increasing maxdepth beyond 1.

want to search for files or folders that begin with the word "abc"

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 with f, or directories with d. 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:

find /Users/YourName/YourData -iname "abc*" -maxdepth 1

Let us know if you have questions.


Some References:

  1. BSD man page for find

  2. Know Your Tools: Linux (GNU) vs. Mac (BSD) Command Line Utilities

Solution 2:

In Finder you can

  • type abc (quickly) to find the first match
  • use Cursor Down to move to the next file. If you keep the Shift key pressed, you select while you move