~2 min read • Updated Jul 16, 2025

Linux uses plain text as the foundation for data representation, logging, configuration, and documentation. To create well-structured output—whether for printing, scripting, or reports—users can rely on formatting utilities designed to control line numbering, wrapping, spacing, and even typesetting.


nl – Number Lines


nl adds line numbers with control over logical page sections and custom numbering formats.


  • Basic usage:
    nl distros.txt
  • Custom numbering:
    nl -n rz -w 3 -s ' '
  • Logical page markup: \\:\\:\\: (header), \\:\\: (body), \\: (footer)

fold – Wrap Lines


fold wraps long lines to a fixed width, useful for display limitations.


echo "Sample sentence here." | fold -w 12 -s

fmt – Format Text Paragraphs


fmt reformats paragraph-style input to a consistent width and spacing, ideal for comments and structured notes.


fmt -w 50 file.txt

fmt -p '# ' file.txt

pr – Prepare for Printing


pr paginates content with headers, page breaks, and margins.


pr -l 15 -w 65 distros.txt

printf – Structured Output


printf formats values using placeholders and field controls, ideal for scripts and reports.


printf "Line: %05d\t%.2f\t%s\n" 7 3.14 "Done"

SpecifierUsage
%dDecimal integer
%fFloating-point
%sString
%x / %XHexadecimal
%%Literal percent sign

groff – Advanced Document Formatting


groff formats documents with macros, supporting output for screen or print (PostScript, PDF).


  • Preview ASCII man page:
    zcat man.1.gz | groff -mandoc -T ascii
  • Generate PDF:
    groff -mandoc man.1 > page.ps
    ps2pdf page.ps page.pdf
  • Create styled tables with tbl:
    groff -t -T ascii formatted-table.txt

Conclusion


Linux formatting tools like nl, fold, fmt, pr, printf, and groff help users present structured output professionally. Whether preparing printed documents, structured terminal data, or formatted scripts, these utilities are indispensable for clear communication in the Unix world.


Written & researched by Dr. Shahin Siami