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
adds line numbers with control over logical page sections and custom numbering formats.
nl distros.txt
nl -n rz -w 3 -s ' '
\\:\\:\\:
(header), \\:\\:
(body), \\:
(footer)fold
wraps long lines to a fixed width, useful for display limitations.
echo "Sample sentence here." | fold -w 12 -s
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
paginates content with headers, page breaks, and margins.
pr -l 15 -w 65 distros.txt
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"
Specifier | Usage |
---|---|
%d | Decimal integer |
%f | Floating-point |
%s | String |
%x / %X | Hexadecimal |
%% | Literal percent sign |
groff
formats documents with macros, supporting output for screen or print (PostScript, PDF).
zcat man.1.gz | groff -mandoc -T ascii
groff -mandoc man.1 > page.ps
ps2pdf page.ps page.pdf
tbl
:groff -t -T ascii formatted-table.txt
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.