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

2. groff to format a html file.
$ groff -Thtml
hello, world!
Save the file by CTRL+D after writing the necessary input.


3. groff with piped output. To pipe the output of groff command use the following command syntax
$ groff -Thtml > o.html
My first webpage


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.

5. groff with .br command. Used to invoke line break in the document.
$groff >> output
Hi
.br
Welcome to GeeksforGeeks

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

7. groff with .bp command. Used to invoke page break within the document.
$groff > output
hi
.bp
welcome to gfg


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!

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

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!!!!

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

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.
Similar Reads
groffer Command in Linux with Examples The groffer command is a powerful utility in Linux used for viewing Groff files and man pages on various platforms, including the X Window System, terminal (tty), and other document viewers. It simplifies the process of displaying formatted documents, allowing users to read and search manual pages o
4 min read
gs command in Linux with Examples gs command invokes Ghostscript, which is an interpreter of Adobe Systems PostScript and Portable Document Format(PDF) languages. After executing Ghostscript it reads further input from the standard input stream until it encounters 'quit' command. Syntax: gs [ options ] [ files ] ... Options: Below a
2 min read
if command in linux with examples if command in Linux is used for conditional execution in shell scripts.The if command is essential for writing scripts that perform different actions based on different conditions.if COMMANDS list is executed, if its status is true, then the then COMMANDS list is executed. Otherwise, each elif COMMA
4 min read
grpconv command in Linux with examples The grpconv command in Linux is used to convert groups to shadow groups. Shadow groups offer enhanced security by moving group passwords into the shadow group file (/etc/gshadow), which is not readable by normal users, thus protecting sensitive information. The grpconv command works by creating or u
5 min read
fgrep command in Linux with examples The 'fgrep' filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings that contain lots of regular expression metacharacters, such as "^", "$", etc. This makes 'fgrep' particularly v
4 min read
grpck command in Linux with Examples grpck command in Linux System verifies the integrity of the groups' information. It checks that all entries in /etc/group and "/etc/gshadow" have the proper format and contain valid data. The user is prompted to delete entries that are incorrectly formatted or which have uncorrectable errors. Syntax
5 min read