Skip to content
Related Articles

Related Articles

groff Command in Linux with Examples
  • Last Updated : 01 Sep, 2020

In Linux/UNIX, Groff stands for GNU troff. Groff is basically used to create man pages. But its functionality is not limited to creating man pages, rather it acts as a formatting and typesetting engine. It acts as a compiler for the input supplied to it and it creates a formatted document as its output. 

Syntax: 

groff [-abcegijklpstzCEGNRSUVXZ] [-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 ...]

Note: To save the file press CTRL+D after writing the required data to the file. 

Working with groff command

1. Using the simple groff command

$ groff
hello world

groff_basic



2. groff to format a html file. 

$ groff -Thtml
hello, world!

Save the file by CTRL+D after writing the necessary input. 

groff format html pagesgroff format html pages

3. groff with piped output.  To pipe the output of groff command use the following command syntax

$ groff -Thtml > o.html
My first webpage

piped grtoff

 

piped groff

4. groff with .sp command. Invokes a specified number of spaces before the required line. 



$ groff > output
Hello world
.sp 10
This line will occur after 10 spaces.

groff .sp command

5. groff with .br command. Used to invoke line break in the document. 

$groff >> output
Hi
.br
Welcome to GeeksforGeeks

groff with .br

6. groff with .ls command. Used to specify the spacing between two lines in the document. 

$groff > output
.ls 2
hello world
.br
welcome to gfg

groff with .ls

7. groff with .bp command. Used to invoke page break within the document. 

$groff > output
hi
.bp
welcome to gfg

groff with .bp

 

8. groff with .ce command. This command is used to position particular lines at the center of the page within the document. 

$ groff > output
.ce 1
This line is pushed towards the center of the document
hello geeks!

groff with .ce

9. groff with .in command. This command is used to maintain the indentation of the content in the document. 

$ groff > output
hi
.br
.in 5
welcome to gfg

groff with .in

10. groff with .ti command. This command is basically a combination of .ce and .br . It can be used to insert a line break and center the immediate next line to ‘n’ steps where n is the argument passed to .ti command. 

groff > output
hello
.ti 5
welcome to geeksforgeeks!!!!

groff with .ti

11. groff with .po command. This command is used to set the page offset ie space between left edge of the document paper and left margin in the document. 

$ groff > output
.po 10
hi
.br
welcome to gfg

groff with .po

12. groff with.ps command. This command is used to set the font size of the text. It can be preceded with – to decrease the font size. To increase the font size no explicit symbol is required before the command. 

groff > output
hi
.br
.ps 25
welcome to my page

groff is mainly used to format documents where groff along with predefined commands produces formatted output on plain text.

My Personal Notes arrow_drop_up
Recommended Articles
Page :