baicai

白菜

一个勤奋的代码搬运工!

Quickly fuzzy search files with MAC commands

find command#

Description: Use the find command to search for files.
Syntax: find ~ -iname "filename*"

/**
* For example, if I want to search for a .zip file that starts with 'vue-',
* but I forgot its full name and the folder it's in,
* and the search range is within the '~' node,
* you can use this method for fuzzy searching.
*/

 find ~ -iname "vue-*.zip"

/**
* Then it will print out all the files and paths that meet the criteria.
*/

find can not only search for files, but also for folders.

/**
* For example, if I want to search for all files or folders that contain 'vue'.
*/
find ~ -iname "*vue*"

/**
* It found all the files or folders that contain 'vue'.
*/

The find method is simple but requires some professional knowledge. You need to know some basic knowledge of regular expressions, specify the path range, and enclose the search name in quotes, etc.

mdfind command#

Description: Use the mdfind command to search for files.
Syntax: mdfind -name filename

/**
* For example, if I want to search for all files or folders that contain 'vue'.
*/
mdfind -name vue

/**
* Look, I just entered the keyword 'vue' that I want to find,
* and it outputs all the files and folders, very convenient, right?
*/

mdfind is straightforward and has no drawbacks, but the prerequisite is that your Mac computer supports Spotlight functionality. However, don't worry, it is usually supported by default on Mac.

Executing Commands in the Shell#

If you have found the file or folder you are looking for, but you want to open it directly, how do you do it? See below.

To run a command in your personal folder as the current user, prefix it with the folder specifier. For example, to run MyCommandLineProg, use the following command:

% ~/MyCommandLineProg

To open an app, use the open command:

% open -a MyProg.app

Terminating a Command#

  • In the Terminal app on your Mac, click the Terminal window that is running the command you want to terminate.

  • Press the Control-C key.

  • This sends a signal that causes most commands to terminate.

References#

Executing commands and running tools in Terminal on Mac [1]

Quickly find files or folders with MAC commands, supports fuzzy search [2]

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.