Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

we use man foo to search about command foo. To know what is it and what its task and to find all switches.

But the point is when you want to Do foo and you do not know what is the command for that. I wish to find among man pages to know which command related to this?

My question :

is there any way to guess what is appropriate command for your need without access to internet and googling? and finding them just by man on the terminal?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

There is no fix method of finding a command. But man -k may help you somewhat.

According to man man

man -k printf
       Search the short descriptions and manual page names for the keyword
       printf  as  regular expression.  Print out any matches.  Equivalent
       to apropos -r printf.

For example, if I want to search for a version control system, I may try

man -k 'version control'|grep ' (1)'

which shows

bzr (1)              - Bazaar next-generation distributed version control

But it did not show git, because it's short description is

git (1)              - the stupid content tracker

which does not match regexp "version control".

share|improve this answer

If you know 'sorta' what your command is related to, you can use the apropos command:

xenon-lornix:~> apropos change directory

alphasort (3)        - scan a directory for matching entries
apt-listchanges (1)  - Show new changelog entries from Debian package archives
avahi-set-host-name (1) - Change mDNS host name
basename (1)         - strip directory and suffix from filenames
basename (1posix)    - return non-directory portion of a pathname
besside-ng-crawler (1) - filter EAPOL frames from a directory of capture files.
bindtextdomain (3)   - set directory containing message catalogs
BN_swap (3ssl)       - exchange BIGNUMs
brk (2)              - change data segment size
can_change_color (3ncurses) - curses color manipulation routines
can_change_color_sp (3ncurses) - curses screen-pointer extension
cd (1posix)          - change the working directory
chacl (1)            - change the access control list of a file or directory
chage (1)            - change user password expiry information
chattr (1)           - change file attributes on a Linux file system
chcon (1)            - change file security context
chdir (2)            - change working directory
chdir (3posix)       - change working directory
... and 400+ more ...

You received this many returns since apropos defaults to or mode... so anything that matches change OR directory is returned. Whew! Too many! (Although I can see the one we want here though)

xenon-lornix:~> apropos --and change directory

cd (1posix)          - change the working directory
chacl (1)            - change the access control list of a file or directory
chdir (2)            - change working directory
chdir (3posix)       - change working directory
chroot (2)           - change root directory
fchdir (2)           - change working directory
fchdir (3posix)      - change working directory
futimesat (2)        - change timestamps of a file relative to a directory file descriptor
git-stash (1)        - Stash the changes in a dirty working directory away
Linux::Inotify2 (3pm) - scalable directory/file change notification
mcd (1)              - change MSDOS directory
revpath (1)          - generate a relative path that can be used to undo a change-directory

This time, we only got 12 results, much better! And you can see the cd (1posix) command which may be useful. man cd or man 1posix cd will show you the man page. And if you use the bash shell (or zsh or whatever...), always check their man pages too. man bash and searching for change will get you close to bash's built-in cd command's description. (keep searching! It's in there!)

apropos gets it's information from a database built each night (cronjob), it really only searches the name and description sections of the man pages. If you REALLY want to search for a keyword, use man -K (uppercase K there):

xenon-lornix:~> man -K M_CHECK_ACTION

(should bring up the man page for mallopt(3))

Do remember that this is a BRUTE-FORCE physical touch and search of EVERY man page on your system. It can take a while! Much faster after everything's been read in and cached though.

Just want a list of man pages with the particular keyword?

xenon-lornix:~> man -K -w MALLOC_CHECK_

/usr/share/man/man3/malloc.3.gz
/usr/share/man/man3/malloc_get_state.3.gz
/usr/share/man/man3/mallopt.3.gz
/usr/share/man/man3/mcheck.3.gz

Found in a few pages there. (Capital Kay, lowercase double-ewe)

Have a look at the man man page too, some interesting variations.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.