Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So it seems that typing man git init into a bash prompt on an Ubuntu 14.04 system does the same as man git-init, only I'm not quite sure how.

The man page for man (i.e. man man) doesn't seem to allow for this construct, unless git was a section of the manual, but the man page seems to come from section 1.

Is this an undocumented usage supported by man? Have I misunderstood the documentation of man? Is some other magic happening? Anyone care to explain?

share|improve this question
    
Appears as though git-init may just be a wrapper for git init – Jeff Schaller Feb 23 at 17:02
4  
7  
@ThomasDickey not sure how this is a duplicate; this asks about the behavior of man, the other questions asks about the behavior of git (though the OP in the other case thinks its a shell feature...) – derobert Feb 23 at 23:09
    
It's been answered before (repeatedly on stackoverflow); I chose the first useful duplicate here that I found. – Thomas Dickey Feb 23 at 23:12
2  
It's quite possible that there is a duplicate of course, but unix.stackexchange.com/questions/76410/… isn't it. My question is different, as explained by @derobert. I don't think an edit is required here. – mc0e Feb 24 at 6:53
up vote 66 down vote accepted

Some implementations of man, including the one used by Ubuntu, replace spaces in its search terms with hyphens and attempt to find a manual page under that name. So man git init looks for the same thing as man git-init. Similarly, man run parts and man ntfs 3g work (if you have run-parts and ntfs-3g on your system).

It only does this with word pairs, though, so man git annex sync does not work (though man git-annex sync does, as that's again a word pair).

In fact, when you ask for two manual pages (e.g., man git bash to see both the git and bash manpages), man actually first tries to look for a git-bash manpage. You can see this in the debug output if you enable it with -d.

This man feature is called "subpages" you can read the source code implementing subpages in man-db (thanks, Stephen Kitt). Searching the man(1) manpage for "subpages" will also lead you to the description of this behavior under the --no-subpages option:

--no-subpages
      By default, man will try to interpret pairs of manual page
      names given on the command line as equivalent to a single
      manual page name containing a hyphen or an underscore.  This
      supports the common pattern of programs that implement a
      number of subcommands, allowing them to provide manual pages
      for each that can be accessed using similar syntax as would be
      used to invoke the subcommands themselves.  For example:

        $ man -aw git diff
        /usr/share/man/man1/git-diff.1.gz

      To disable this behaviour, use the --no-subpages option.

        $ man -aw --no-subpages git diff
        /usr/share/man/man1/git.1.gz
        /usr/share/man/man3/Git.3pm.gz
        /usr/share/man/man1/diff.1.gz
share|improve this answer
    
This seems to not work on CentOS 6.6. Is it Ubuntu only? – Wildcard Feb 23 at 21:59
1  
@Wildcard which part seems to not work? It should work as long as CentOS is using man-db (there are other man implementations), and subpages haven't been disabled (e.g., with --no-subpages). I'm using Debian, so it definitely isn't just Ubuntu. – derobert Feb 23 at 23:06
2  
The important thing is that this is unique to a specific implementation of man. It is by no means universal or particular common. – chepner Feb 24 at 15:25

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.