
grn Command in Linux
The grn is a preprocessor command line utility in Linux that is used to add Gremlin pictures into groff documents. The grn command enables us to embed graphical elements in our documents. This command reads lines between the ".GS" and ".GE" markers and writes to standard output. These lines must contain a grn command between them.
In this tutorial, well explore what is grn and how it works in Linux.
Table of Contents
Here is a comprehensive guide to the options available with the grn command −
- Installation of grn Command
- What is grn Command?
- Syntax of grn Command
- Options grn Command
- grn Command Manual Page
- Examples of grn Command in Linux
Installation of grn Command
The grn command belongs to the groff package that is not pre-installed on most Linux distributions. To install it on Debian or Ubuntu, you must run the following commands one by one:
sudo apt update sudo apt install groff
Similarly, you can use a suitable package manager depending upon your Linux distribution to install the groff package (including the grn command) on your system.
What is grn Command?
The grn command stands for Gremlin, which is a graphical format used in early Unix systems. It is a Groff preprocessor utility for Gremlin files. It reads input lines from stdin. These lines must be between ".GS" and ".GE" and may have one grn command. Moreover, these lines contain commands that tell grn which Gremlin file to use, and the picture from that file is added to the document.
We can add a letter C, L, or R after the ".GS" marker to place the picture in the center, left, or right. By default, the picture is positioned in the center. If no file is provided, it reads from the stdin.
Moreover, these commands usually have one or two strings separated by a space. The first string is the command, and the second string (if there is one) is its operand. You can write commands in uppercase or lowercase, and they can be shortened to one letter.
Syntax of grn Command
You can use the grn command with the following syntax −
grn [ -C ] [ -Tdev ] [ -M ] [ -F ] [ file... ]
Options grn Command
You can have spaces between a command line option and its value. The available options for this command are listed in the following table along with respective descriptions:
Option | Description |
---|---|
-T dev | It prepares the output for the specified printer device, with the default being ps. |
-M | It lets us define a directory (dir) where grn will search for input or include files. It helps keep resources organized. |
-F | It is similar to the -M option, but used for output files. It allows us to set the directory where grn will store its output. |
-C | It lets us recognize ".GS", ".GE", and ".GF" even when followed by a character other than a whitespace or a newline. |
-v, --version | It returns the version number of the grn command. |
grn Command Manual Page
You can access the grn commands official manual page by running the following command:
man grn
The general commands manual shows the command name, synopsis, description, and available options along with their working:

Examples of grn Command in Linux
In this section, we will understand how to use the grn command in Linux using basic to advanced examples −
- Processing a Gremlin File Using grn Command
- Specifying the Output Device Type
- Searching Input Files from a Specific Directory
- Redirecting the Output to a Specific Directory
- Using Multiple Options with the grn Command
- Processing Multiple Files with the grn Command
- Integrating GRN with Groff
Processing a Gremlin File Using grn Command
In the following example, we run the grn command on a gremlin file named inputFile.gremlin:
grn inputFile.gremlin
This command will process the given file and return the result to the standard output.
Specifying the Output Device Type
We can use the grn command with the -T option to specify an output device type:
grn -Tps inputFile.gremlin > outputFile.ps
This command reads input from the inputFile.gremlin, processes it, and redirects the output to a PostScript file named outputFile.ps.
Searching Input Files from a Specific Directory
We can execute the grn command with the -M option to search an input file from the specified directory:
grn -M /path/to/directory inputFile.gremlin
You can replace the /path/to/directory with the home directory, /usr/lib64/groff/site-tmac, /usr/share/groff/site-tmac, or /usr/share/groff/1.18.1.4/tmac as needed.
Redirecting the Output to a Specific Directory
You can use the -F option with the grn command to specify the output directory for processed files:
grn -F /path/to/outputDir inputFile.gremlin
You can replace the "/path/to/outputDir" with /usr/share/groff/site-font, /usr/share/groff/1.18.1.4/font, or /usr/lib/font.
Using Multiple Options with the grn Command
You can run the grn command with the multiple options combined to control input and output directories and specify the output format:
grn -M /input/directory -F /output/directory -Tpdf inputFile.gremlin
This time, the grn command processes "inputFile.gremlin", searches for input files in the /input/directory, and saves the output as a PDF file to the /output/directory.
Processing Multiple Files with the grn Command
You can specify multiple Gremlin files with a space-separated syntax to process them simultaneously:
grn inputFile1.gremlin inputFile2.gremlin inputFile3.gremlin > finalOutput.ps
This command processes all the input files and combines the output into a single PostScript file named finalOutput.ps.
Integrating GRN With Groff
We can use the grn command with groff to process the documents that include graphics:
groff -p -t -grn inputFile.groff > outputFile.ps
Here, the groff command is used to process a document named inputFile.groff, which includes Gremlin graphics, and creates a PostScript output.
This way, you can use the grn command in Linux to process Gremlin pictures into groff documents.
Conclusion
The grn command allows you to integrate Gremlin pictures into Groff documents. It offers options to control input and output directories. You can also specify output formats. By following the provided examples, you can efficiently process Gremlin files. You can use different device types and integrate graphics into your documents.
In this tutorial, we covered the basics of the grn command in Linux. We discussed its installation and provided various examples of how to use it effectively.