Skip to content

Manpage Explained

Scover edited this page Apr 9, 2025 · 3 revisions

Manpage Explained

Introduction

"Manpages used to confuse me. Now they just mildly intimidate me."
— everyone, at some point

This page demystifies the argc(1) manpage and gives you a friendly introduction to:

  • What manpages are
  • How they’re written and formatted
  • How to write one yourself (without losing your mind)
  • The mysterious world of .TH, .SH, and .B
  • Why troff isn’t as scary as it sounds

Even if you’re not writing low-level system tools, understanding manpages is a rite of passage in Unix-like systems—and a great exercise in clear, minimal, offline-friendly documentation.

What is a manpage?

“manpage” is short for manual page. It’s a small document—usually accessed with the man command—that tells you:

  • What a command does
  • How to use it
  • What options it accepts
  • What bugs or quirks it might have

You read them like this:

man ls
man 2 write
man argc

They're stored in numbered sections:

Section Contents
1 User commands (e.g. ls)
2 System calls (write, open)
3 C library functions
5 File formats (crontab, fstab)
7 Miscellaneous conventions
8 Admin-only commands

argc lives in section 1, like most userland tools.

How are manpages written?

Manpages are written in troff, a typesetting language older than some operating systems. Most modern manpages use a simplified macro package for troff called man(7).

It’s… weird-looking at first:

.TH ARGC 1 "April 2025" "argc 1.0" "User Commands"
.SH NAME
argc \- print the number of arguments passed

But it’s basically just semantic markup, like HTML, without the angle brackets.

You don't need a troff degree to write a manpage. If you copy-paste a template and modify a few lines, you're already doing better than many tools out there.

How to write a good manpage

✅ DO

  • Keep it minimal and factual
  • Include usage examples in the DESCRIPTION
  • Explain every option in OPTIONS (if you have them)
  • Always define NAME and SYNOPSIS
  • Include author, license, and where to report bugs
  • Respect line width: ~80 characters max

❌ DON'T

  • Be vague ("this tool processes files"…)
  • Forget to mention default behaviors
  • Assume users know anything
  • Make it funny instead of helpful (unless you’re argc, of course)

A very tiny intro to TROFF

Troff macros are line-based and start with a dot (.)

.TH   ← Title Header
.SH   ← Section Header
.B    ← Bold text
.I    ← Italic text
.BR   ← Bold + Roman

Other formats exist (mdoc, groff, mandoc), but .TH/.SH/.B is what most Linux tools use.

To preview a manpage you've written:

man ./argc.1

Or convert to plain text:

man ./argc.1 | col -bx

Section-by-section breakdown of argc.1

Let’s look at the real argc manpage:

.TH — Title Header

.TH ARGC 1 "April 2025" "argc 1.0" "User Commands"
  • ARGC – the command name
  • 1 – the manual section
  • "April 2025" – date of this version
  • "argc 1.0" – version string
  • "User Commands" – section header footer

This line sets the document's metadata and formats the header/footer when viewed via man.

.SH NAME

.SH NAME
argc \- print the number of arguments passed

This is required. It's used in man -k and apropos.

  • The dash (\-) separates the name from the summary.
  • Write the description in plain English—keep it short and searchable.

.SH SYNOPSIS

.SH SYNOPSIS
.B argc
.IR ARGUMENT ...
  • .B makes argc bold (a command)
  • .IR ARGUMENT ... renders ARGUMENT... in italics followed by roman dots
  • This section shows how to run the command

.SH DESCRIPTION

.SH DESCRIPTION
Prints the number of command-line arguments passed to the program in base 10, followed by a newline.

This is where you explain what the program does, with maybe an example or edge case notes.

In argc:

.B argc foo bar baz
will output:
.B 3

You can use .B again to format examples.

.SH AUTHOR, .SH REPORTING BUGS, .SH LICENSE

These are conventional—but optional—sections for attribution and maintenance:

.SH AUTHOR
Written by Scover.

.SH REPORTING BUGS
Report issues at:
.BR https://github.com/5cover/argc

.SH LICENSE
This is free and unencumbered software released into the public domain.

The .BR macro prints bold text followed by normal text on the same line.

Final Thoughts

Manpages aren’t magic. They're just:

  • Plain text files
  • Written with weird-but-readable macros
  • Installed in /usr/share/man/man1/ or similar
  • Rendered by the man command using a pager

Once you write one, you’ll never look at man the same again.

And argc gave us a perfect excuse to build one from scratch—because why not?

See also

Want to try it yourself? Copy argc.1, rename it, and start tweaking. You’ll be a Unix wizard in no time.