nroff

text processinglinux
The nroff command is one of the most frequently used commands in Linux/Unix-like operating systems. nroff The nroff command is a text formatting program for Unix/Linux that formats documents for display on terminals and line printers. It's a component of the groff document formatting system specifically tailored for producing plain text output.

Quick Reference

Command Name:

nroff

Category:

text processing

Platform:

linux

Basic Usage:

nroff [options] [arguments]

Common Use Cases

  • 1

    Document formatting

    Create formatted documents using the nroff typesetting system

  • 2

    Report generation

    Generate professional-quality reports and documents

  • 3

    Scripting

    Use in shell scripts to generate formatted documents programmatically

  • 4

    Document processing

    Manipulate and transform document data

Syntax

nroff [OPTION]... [FILE]...

Options

Option Description
-e Preprocess with eqn (for mathematical formulas)
-h Use output tabs instead of spaces
-i Read standard input after processing all files
-m PACKAGE Use macro package PACKAGE (e.g., -man, -ms, -mm)
-n N Number first page N
-o LIST Output only pages in LIST
-p Preprocess with pic (for diagrams)
-r REG=VAL Set register REG to VAL
-s Preprocess with soelim (for file inclusion)
-t Preprocess with tbl (for tables)
-T NAME Prepare output for device NAME
-U Unsafe mode (enable potentially dangerous operations)
-V Print version information
-w Enable warning messages
-W LEVEL Set warning level to LEVEL
-Z Suppress formatted output (useful for checking syntax)

Examples

How to Use These Examples

The examples below show common ways to use the nroff command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

nroff -man man_page.1

Format a man page for terminal display. This is the traditional way to format manual pages for viewing directly in a terminal window.

nroff -ms document.ms > document.txt

Format a document written with ms macros and save the output to a text file. The ms macro package is designed for general document formatting.

man ls | col -b > ls.txt

Capture a formatted man page to a text file. This command pipes the man page through col to remove backspace characters and other formatting artifacts.

nroff -t -e -man manpage.1 | less

Format a man page with table and equation processing and view with less. The -t and -e options enable the tbl (table) and eqn (equation) preprocessors.

Advanced Examples:

nroff -ms -rW60 document.ms

Format a document with a specific line width of 60 characters. The -rW60 option sets the line width register to 60 characters for a narrower output.

nroff -t -pet -ms technical_doc.ms | less

Process a technical document with tables, equations, and diagrams for terminal display. This combines multiple preprocessors (tbl, pic, eqn) for handling complex document elements.

echo ".TL\nHello World\n.PP\nThis is a test." | nroff -ms

Process a simple document provided directly as input. This demonstrates how nroff can format text directly from the command line for quick text formatting tasks.

nroff -mm -rN2 memorandum.mm > memo.txt

Format a memorandum document with mm macros and modify page numbering. The -rN2 option starts page numbering from 2 instead of the default 1.

cat script.roff | nroff | col -bx > formatted.txt

Format a raw roff document and save as clean text. This pipeline processes a roff file and removes any backspace characters and tab issues with col.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

What Nroff Does:

  • Formats text documents for terminal display and line printers
  • Generates plain text output from marked-up input files
  • Processes the same input files as groff but produces character-oriented output
  • Serves as the backend for the man command to display manual pages
  • Supports various macro packages for different document types
  • Works with preprocessors for tables, equations, and other elements

Common Use Cases:

  • Formatting man pages for terminal display
  • Creating plain text documentation from structured source files
  • Converting roff documents to terminal-friendly formats
  • Generating reports and documents for text-only environments
  • Preparing technical documentation for terminals and line printers
  • Creating text-only versions of documents that preserve structure

Macro Packages:

  • man: For Unix manual pages (-man)
  • ms: General-purpose document formatting (-ms)
  • mm: Memorandum macros for business documents (-mm)
  • me: Macros for papers and theses (-me)
  • mdoc: Semantic macros for BSD documentation (-mdoc)

Preprocessors:

  • tbl: For creating tables (-t)
  • eqn: For mathematical equations (-e)
  • pic: For line drawings and diagrams (-p)
  • refer: For bibliographic references (-R)
  • soelim: For including external files (-s)

Relationship to Other Commands:

  • groff: nroff is part of the GNU groff system, which is a modern implementation of Unix troff
  • troff: Like nroff but produces typesetter output rather than terminal output
  • man: Uses nroff to format manual pages for display
  • col: Often used to post-process nroff output to remove backspaces and other formatting artifacts
  • less/more: Common pagers used to view nroff-formatted output

History and Context:

  • nroff stands for "new runoff," a successor to the original runoff program
  • It was developed at Bell Labs as part of the Unix document processing tools
  • In modern systems, nroff is typically implemented as a script that calls groff with appropriate options
  • Despite being decades old, it remains essential for Unix/Linux documentation
  • The man page system relies on nroff/troff formatting commands

Related Commands:

  • groff - GNU document formatting system (modern implementation including nroff)
  • troff - Typesetter version of nroff for high-quality printed output
  • man - Interface to the system manual pages
  • col - Filter reverse line feeds from nroff output
  • tbl - Table preprocessor for nroff/troff
  • eqn - Equation preprocessor for nroff/troff
  • pic - Picture preprocessor for nroff/troff

Tips & Tricks

1

Use the -T device option to specify the output device

2

Use the -m device option to specify the input device

3

Use the -r resolution option to specify the resolution

4

Use the -p paper option to specify the paper size

5

Use the -h option to display help

Common Use Cases

Document formatting

Create formatted documents using the nroff typesetting system

Report generation

Generate professional-quality reports and documents

Scripting

Use in shell scripts to generate formatted documents programmatically

Document processing

Manipulate and transform document data

Typesetting

Create high-quality typeset documents

Related Commands

These commands are frequently used alongside nroff or serve similar purposes:

Use Cases

1

Document formatting

Create formatted documents using the nroff typesetting system

2

Report generation

Generate professional-quality reports and documents

3

Scripting

Use in shell scripts to generate formatted documents programmatically

4

Document processing

Manipulate and transform document data

5

Typesetting

Create high-quality typeset documents

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the nroff command works in different scenarios.

$ nroff
View All Commands