6

I can do for example

man cp | grep verbose

to findout if cp man has word "verbose", how can I do something like (pseudo-code)

man * | grep copy

to find out what command to use for coping?

1
  • 2
    man has its own man page ;)
    – Rinzwind
    Nov 17, 2011 at 15:40

5 Answers 5

6

You can use

man -K printf

(note the capital k) to search in content of man all man pages. The first page will be shown, and when you quit you have the option to open or skip the next matching page or quit the whole search.

1
  • This is the correct answer.
    – bukzor
    Sep 3, 2021 at 15:47
5

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.

Or as you can see you can also use apropos -r printf

Example...

man -k "test"

Test (3perl)         - provides a simple framework for writing test scripts
cupstestdsc (1)      - test conformance of postscript files
cupstestppd (1)      - test conformance of ppd files
DBD::Gofer::Transport::null (3pm) - DBD::Gofer client transport for testing
DBD::Gofer::Transport::pipeone (3pm) - DBD::Gofer client transport for testing
dh_auto_test (1)     - automatically runs a package's test suites
dh_testdir (1)       - test directory before building debian package
dh_testroot (1)      - ensure that a package is built as root
dh_testversion (1)   - ensure that the correct version of debhelper is installed
ExtUtils::testlib (3perl) - add blib/* directories to @INC
feature_test_macros (7) - feature test macros
File::CheckTree (3perl) - run many filetest checks on a tree
filetest (3perl)     - Perl pragma to control the filetest permission operators
ftm (7)              - feature test macros
gcov-4.2 (1)         - coverage testing tool
make-memtest86+-boot-floppy (1) - (unknown subject)
Memoize::ExpireFile (3perl) - test for Memoize expiration semantics
Memoize::ExpireTest (3perl) - test for Memoize expiration semantics
mysql_client_test (1) - test client API
mysql_client_test_embedded (1) - test client API for embedded server
mysqlmanager-pwgen (1) - internal test-suite program
mysqlmanagerc (1)    - internal test-suite program
mysqltest (1)        - program to run test cases
mysqltest_embedded (1) - program to run embedded test cases
ndb_cpcd (1)         - automate testing of NDB (development use only)

4

You can use

  man -k copy

to search in the short descriptions and names of all manpages for copy

3
  • That solves the second part of the question. For the first part, there are a couple of options. 'man cp | cat | grep verbose' will just get the particular lines containing the word verbose. You can also type /verbose when you're in the man page to do a pattern match for the word 'verbose'. After that, if you keep pressing 'n', it will cycle you through all the occurences of the word verbose in the file.
    – ovangle
    Nov 17, 2011 at 15:45
  • 1
    ovangle - that cat is superfluous.
    – ams
    Nov 17, 2011 at 16:12
  • So it is. Stupid me, that's a whole 5 keystrokes I've wasted every time I've grepped a man page (never -- I prefer some context with my flags, so '/' is more useful).
    – ovangle
    Nov 17, 2011 at 17:09
4

You can also zgrep -r each location in manpath to search the raw manpage files.

for p in $(manpath | tr ":" " ");
do
    echo $p
    zgrep -r 'copy' $p
done
3
  • Except that a) MANPATH is upper case and often not set, and b) many man-pages are compressed and therefore not grep-able.
    – ams
    Nov 17, 2011 at 16:09
  • 1
    a) manpath is a command (it might also be a ENV, but I'm talking about the command) and b) good point, I'll swap it for zgrep which works on both the compressed and non-compressed files.
    – Oli
    Nov 17, 2011 at 16:29
  • 1
    Ah, I did not know about manpath as a command. Learn something new every day. But zgrep doesn't support -r, so try this: find $(manpath | tr ":" " ") -type f -print0 | xargs -0 zgrep 'copy'
    – ams
    Nov 17, 2011 at 20:09
3

Try this:

man * | col -b | grep *
3
  • As the OP mentioned, man * does not do what he wants.
    – jpaugh
    Feb 12, 2019 at 22:47
  • what's the difference of man command | grep "keyword" AND man command | col -b | grep "keyword" ? When I tried "man grep | grep -i "case" " AND "man grep | col -b | grep "case" ", I couldn't find any difference. When will piping through "col -b" make a difference ?
    – anjanb
    Oct 18, 2019 at 9:50
  • ANSWER : I did a hex compare of the output of both above commands (with and without "col -b" command pipe) and found that without "col -b", there's additional characters in the output, I presume coming from the man content. So, yes, it helps to do a "col -b"
    – anjanb
    Oct 18, 2019 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .