Search for commands by keyword in the Terminal

Apr 12, '02 08:34:44AM

Contributed by: seven5

This trick may be obvious, but by combining a couple commands in the Terminal, you can search the descriptions of all the commands in that path. Open a Terminal and type:

 % whatis /usr/bin/* | grep "search string"
This will return the description of every command in that path and then filter it with your search string. This is a quick way to find a way of doing something, if you don't know all the commands. For example:
 % whatis /usr/bin/* | grep "memory"
leaks(1) - Search a process's memory for...
vm_stat(1) - show Mach virtual memory statistics
vmmap(1) - Display the virtual memory regions...
These example results were trimmed for width, but you get the idea...

[Editor's note: You can use this syntax to find anything on any path, of course. If you're just interested in user commands, you could also use man -k "search string" | grep \(1 to return the same results a bit faster. The 'whatis' version of the command will also only work if you have built the whatis databases - see this hint for more about the 'whatis' database.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020412083444156