Why are there different paths for a command in the Synopsis section of a Man Page

grepmansystem-installation

Looking at the man page for grep I noticed there are two different paths to the command. Does this mean I have multiple grep tools on my system? Are the synopsis lines that have the same path just different usage examples of the same tool? I am using OS X 10.10.5

NAME
     grep - search a file for a pattern

SYNOPSIS
     /usr/bin/grep [-bchilnsvw] limited-regular-expression
          [filename]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] -e pattern_list...
          [-f pattern_file]... [file]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx]
          [-e pattern_list]... -f pattern_file... [file]...

     /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] pattern
          [file]...

DESCRIPTION
     The grep utility searches  text  files  for  a  pattern  and
     prints  all lines that contain that pattern.  It uses a com-
     pact non-deterministic algorithm.

A follow up question: Where do man pages come from? Are they generated dynamically or are they part of a static installation?

Best Answer

You say you're on a macOS machine, but the manual looks suspiciously like the grep manual on a Solaris machine. Here is the manual for grep on OSX 10.9 for comparison.

On Solaris, there are several utilities with multiple implementations, and grep is one of them. The ones in /usr/bin adhere to XPG3, which is short for "X/Open Portability Guide, Issue 3". The Single Unix Specification is based on XPG4 (ref: Wikipedia X/Open article)

The XPG3 grep in /usr/bin does, for example, not support extended regular expressions, while the XPG4 grep in /usr/xpg4/bin does.

If a utility has several synopsis lines in its manual, then these are usually describing mutually exclusive ways to invoke the tool.

These:

/usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] -e pattern_list...
      [-f pattern_file]... [file]...

 /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx]
      [-e pattern_list]... -f pattern_file... [file]...

.. show that you may use either -e or -f (or both) but that you must use one of them.

The last one,

 /usr/xpg4/bin/grep [-E | -F] [-c | -l | -q] [-bhinsvx] pattern
      [file]...

... shows that if you use neither -e nor -f, then the pattern needs to be specified on the command line.

See also standards(5) on Solaris.


Manuals are installed "statically", i.e. as separate files that the man command reads and displays. However, depending on your system, some of them may be groff or mandoc source files, while others may be pre-formatted as text files, sometimes stored in a sibling directory to the unformatted manuals, often called something like cat. They may sometimes also be compressed. Read the man manual on your system (man man) to see how manuals are handled there.

Most often, manuals may be found in /usr/share/man, /usr/local/share/man, or some such location.

Related Question