≡ Menu

Linux Groff Command Examples to Create Formatted Document

Groff stands for GNU troff. Groff is typically used to create man pages. But, it does more than that. Its an old school utility which has been around for almost 20 years but still holds its presence.

As a formatting and typesetting engine, this utility acts like a compiler for the input supplied (plain text content and formatting commands) to it and it creates a formatted document as its output. In this article we will understand the basics of this command by discussing some common groff requests along with examples.

Here is the syntax of this command :

groff [-abcegiklpstzCEGNRSUVXZ] [-d cs] [-D arg] [-f fam] [-F dir] [-I dir] [-K arg] [-L arg] [-m name] [-M dir] [-n num]
[-o list] [-P arg] [-r cn] [-T dev] [-w name] [-W name] [file …]
groff -h | –help
groff -v | –version [option …]

1. Basic Groff Example

This example uses groff utility to create a document with a single line without any formatting.

$ groff > grof_output_1
Hi, this is a Line.

This command would produce a PostScript file (PS file) that can be opened in a document viewer.

2. Introduce line spacing using .sp command

If a line space needs to be introduced, use .sp command followed by the number of line spaces required.

$ groff > grof_output_2
.sp 10
This line will occur after 10 spaces.

3. Request a break using .br command

For a regular line break, use .br command as shown below.

$ groff > grof_output_3
Welcome to TGS!

4. Change line spacing using .ls command

Line spacing for a document can be changed using .ls command followed by the number of line spacing to be introduced. By default the Line spacing is 1.

$ groff > grof_output_4
.ls 2
Welcome to TGS!

This document will look like the following when viewed in a document viewer:

5. Introduce a break page using .bp command

If it is intended to have the next line or paragraph from the next page of the document then .bp command is used.

$ groff > grof_output_5
Welcome to TGS!

6. Center lines using .ce command

If some lines need to be pushed towards the center of the document then .ce command can be used.

The argument to .ce determines how many lines need to be pushed to center.

$ groff > grof_output_6
.ce 1
Hello and welcome to TGS.

7. Set indentation using .in command

If indentation needs to be changed then this can be done through .in command followed by the indentation index.

$ groff > grof_output_7
.in 4
Welcome to TGS!

This document will look like the following when viewed in a document viewer:

8. Combine .br and .ce using .ti

This command can be used to break the text and center the immediate next line to ‘n’ steps. Where ‘n’ is the argument passed to .ti command.

$ groff > grof_output_8
.ti 5
Welcome to TGS!

9. Set page offset using .po command

If page offset ie space between left edge of the document paper and left margin in the document needs to be set then .po command can be used.

$ groff > grof_output_9
.po 10
Welcome to TGS!

10. Set the font size using .ps command

If the text needs to be increased or decreased in size then .ps command can be used. Please note that you can precede the argument to .ps with – to decrease the font size

$ groff > grof_output_10
.ps 20
Welcome to TGS!

This document will look like the following when viewed in a document viewer:

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Jalal Hajigholamali September 27, 2012, 9:25 am


    Thanks a lot,
    Very useful article,,,

  • Júlio Hoffimann Mendes September 28, 2012, 4:40 am

    Good to know about this tool, thanks.


  • J.O. October 2, 2012, 11:18 am

    Does anybody know if there is a mobi or epub output module. Kinda like the tbl preprocessor.