Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Search for commands by keyword in the Terminal UNIX
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.]
    •    
  • Currently 2.50 / 5
  You rated: 1 / 5 (4 votes cast)
 
[4,888 views]  

Search for commands by keyword in the Terminal | 7 comments | Create New Account
Click here to return to the 'Search for commands by keyword in the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
apropos
Authored by: zerologic on Apr 12, '02 09:46:47AM

in the terminal, type: apropos memory

You'll get the same list for everything appropriate. :)



[ Reply to This | # ]
Clones...
Authored by: robg on Apr 12, '02 10:54:52AM

apropos is the same as 'man -k', if I'm not mistaken -- the output is identical from both commands for any given keyword. Regardless of which version of the command is used, I still prefer to add the "grep" on the end to restrict the answers to programs which I can run, as opposed to all commands which contain the keyword.

-rob.



[ Reply to This | # ]
Clones...
Authored by: Doc_Gyneco on Apr 13, '02 02:08:56PM
Tks. This is a great tip for those of us who want to learn Unix the casual way. Being the lazy type, I dropped the following in my aliases.mine:
alias whatisit 'man -k !* | grep
Now I simply type in terminal %whatisit memory and tada!

[ Reply to This | # ]
Re: Clones...
Authored by: ldeck on Apr 14, '02 08:48:12PM

Hi there,

that doesn't work.

Your missing a closing quotation - and grep hasn't been given any conditions.

so,
alias whatever 'man -k -' gives the result of typing man -k searchstring at the prompt.

alias whatever 'man -k - | grep' gives the same result as above - no conditions for grep...

alias whatever 'man -k - | grep /(1' says that there are too many ('s

why?



[ Reply to This | # ]
Re: Clones...
Authored by: ldeck on Apr 14, '02 09:04:08PM

Hehe - had the slash the wrong way....

alias manf 'man -k !* | grep (1' does the trick.



[ Reply to This | # ]
corrected
Authored by: Doc_Gyneco on Apr 15, '02 11:12:43PM
Sorry I missed the end of the code at the end of my post (gobbled by my html tags):
alias whatisit 'man -k !* | grep (1'
Hope nobody scratched his head too long on that one, sorry!

[ Reply to This | # ]
Actually...
Authored by: serversurfer on Apr 18, '02 07:40:31AM
'apropos' and 'man -k' both use the whatis database. man also give you the option of limiting your search to certain sections of the man entries.
1. User Commands
2. System Calls
3. Library Calls
4. Special Files
5. File Formats
6. Games (not much there, unfortunately)
7. Macros and Conventions
8. Administrative Commands
9. Kernel Interface
This is especially useful for getting at the deeper entries (try 'man passwd', then 'man 5 passwd'), but it is also relevant to this discussion. man allows you to search multiple sections with the -S flag, and there are "commands you can use" in section 8 as well, (if you can sudo, that is). Oh well. Now that I am trying to test this, I discover that the section limit doesn't work with the -k option. I was trying to save you guys a grep. Nevermind. :( Just don't forget about section 8, that's where all the "hardcore" (fun) stuff is. (5 is pretty useful for figuring out config files and such.) Anyway try this alias:
alias apro 'apropos !* | grep -E "(1)|(5)|(8)"'
That will get you info from all the "good" sections. If you REALLY want to search the mans, GNU man has -K (that's capital 'K'). This searches through the full text of each man page to match your search string! (not just the description headers) Keep in mind, this will take a VERY long time. Love, The Surfer

[ Reply to This | # ]