Linux fmt command

Updated: 05/04/2019 by Computer Hope
fmt command

On Unix-like operating systems, the fmt command is a formatter for simplifying and optimizing text files.

This document covers the GNU/Linux version of fmt.


fmt reformats each paragraph in the FILE(s) specified, writing to standard output. The option -WIDTH is an abbreviated form of --width=DIGITS.


fmt [-WIDTH] [OPTION]... [FILE]...


-c, --crown-margin preserve indentation of first two lines.
-p, --prefix=STRING reformat only lines beginning with STRING, reattaching the prefix to reformatted lines.
-s, --split-only split long lines, but do not refill them.
-t, --tagged-paragraph indentation of first line different from second.
-u, --uniform-spacing Use one space between words, two spaces after sentences.
-w, --width=WIDTH maximum line width (default of 75 columns).
-g, --goal=WIDTH goal width (default of 93% of width).
--help display a help message and exit.
--version Display version information and exit.

If no FILE is specified, or if FILE is a dash ("-"), fmt reads from standard input.


fmt myfile.txt

Display a reformatted version of the file myfile.txt.

fmt < myfile.txt > myfile2.txt

Reformat myfile.txt, and write the output to the file myfile2.txt.

nroff — Format documents for terminal display or line-printer.