1

Today I have read two answers about which regular expressions are supported by less: Where is less search pattern reference?

  • Kusalananda mentioned re_format(7) and referenced its manpage as man 7 re_format.

    RE_FORMAT(7)           Miscellaneous Information Manual           RE_FORMAT(7)
    
    NAME
         re_format – POSIX 1003.2 regular expressions
    
    DESCRIPTION
         Regular expressions (“REs”), as defined in IEEE Std 1003.2 (“POSIX.2”),
         <...>
    
  • ilkkachu mentioned regex(7) and referenced its manpage by providing a link to a web page instead.

    regex(7)            Miscellaneous Information Manual            regex(7)
    
    NAME
         regex - POSIX.2 regular expressions
    
    DESCRIPTION
         Regular expressions ("RE"s), as defined in POSIX.2, <...>
    

I try to figure out how to open the regex(7) manpage from the shell instead of reading it on the web.

man regex7, man regex(7), man 7 regex, man7 regex just don't work, and man regex leads to the regex(3) manpage instead.

4
  • 1
    It's possible you don't have that manpage on your system. You could search with man -k regex. That will give you a lot of pages (potentially including Tcl and other stuff). If you don't see regex (7) on that list then you don't have it. Commented Aug 14 at 19:50
  • @steeldriver Fixed. macOS, Zsh.
    – jsx97
    Commented Aug 14 at 19:52
  • 1
    well, in my defense, I did mention Debian there. regex(7) is the name of the manpage I've seen there, though re_format(7) also looks to appear as a link to the same manpage. BSDs seem to only have re_format(7) (e.g. FreeBSD) And macOS is somewhat BSD-ish.
    – ilkkachu
    Commented Aug 14 at 20:03
  • @ilkkachu Thanks. This is in fact the answer.
    – jsx97
    Commented Aug 14 at 20:10

1 Answer 1

3

The command for displaying the man page for foo in section 7 is man 7 foo. The syntax foo(7) is how references to that man page are usually written.

The section numbers and page names are not the same on every unix flavor.

Commands that you can invoke from the shell generally have a man page by the same name in section 1, but even that has many exceptions, such as:

  • Many programs don't come with man pages, especially if they aren't meant to be used from the command line.
  • Programs intended to be used by administrators may be in a different section (8 on Linux and BSD, 1m on Solaris).
  • Many operating systems don't provide man pages for shell built-ins. Look in the shell's man page instead.
  • A few programs with a complex command line or with a lot of documentation split their man page. The other pages generally have a name that starts with a command (but there are exceptions). For example zsh(1) only covers a few topics and the rest is in zshbuiltins(1), zshzle(1) and so on; perl has even more separate pages; openssl(1) refers you to a separate man page for each subcommand; etc.

C library functions generally have a man page by the same in section 3. C functions that are direct wrappers around system calls, or that were historically so, are in section 2 instead. A few projects ship man pages for C functions in a 3something section, e.g. 3posix, 3pcap, etc. Libraries in a few other languages come with man pages in section 3something, e.g. 3tcl for TCL functions. Some languages have e.g. 3perl for standard Perl modules, 3pm for third-party Perl modules, 3erl for Erlang modules, etc.

Section 7, on most unix flavors, contains “miscellaneous” man pages. You can't expect consistent names and content from one flavor to the next.

Linux distributions normally provide the man pages from the Linux man-pages project. Although it's hosted on the Linux kernel web site, that project includes a lot of non-kernel-related documentation, including GNU libc and miscellaneous topics such as regular expression syntax. man7.org has the same maintainer and shows the Linux man-pages man pages and more.

The Linux man-pages project has a page regex(7) that documents regular expression syntax. BSD systems have a page with similar content, but called re_format(7). The list of pages in section 7 on Linux and FreeBSD is pretty different, that's just one of many differences between two operating systems. On Solaris the set is yet again different, and even the section number is different: 5 is for miscellaneous, while 7 is for devices.

You can run apropos regular expressions to look for manual pages that discuss regular expressions. That includes a lot of commands and functions that use a regular expression in some way, so you may want to restrict the search to the miscellaneous section. On Linux, you can do that with apropos -s7 regular expressions. On macOS, neither apropos nor man -k seem to support restricting to a section, but you can filter: apropos regular expressions | grep '(7)'.

Also, both the regex(3) and grep(1) man pages, both on Linux and macOS, have a reference to the page in section 7 that documents the regular expression syntax.

1
  • Note that on some systems (like on Solaris, though they might also accepts man 7 regex now; though if they do, that's not documented for Solaris 10), that's man -s 7 regex. Commented Aug 15 at 6:52

You must log in to answer this question.

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