$linuxjunkies
>

fmt(1)

fmt reformats text to a specified line length, wrapping paragraphs and removing extra whitespace.

UbuntuDebianFedoraArch

Synopsis

fmt [OPTION]... [FILE]...

Description

fmt reads text from files or standard input and reformats it into lines of a specified width (default 75 characters). It joins short lines, breaks long lines, and removes extra spaces while preserving paragraph breaks (blank lines).

fmt is useful for cleaning up poorly formatted text, fixing indentation issues, and preparing documents for display or printing with consistent line lengths.

Common options

FlagWhat it does
-w WIDTHSet maximum line width to WIDTH characters (default 75)
-cCenter-justify lines instead of left-justifying
-uUniform spacing: one space between words, two after sentences
-sSplit lines only; do not join short lines
-tTest mode; don't actually format, just check validity
-mPreserve indentation of first two lines (mail quoting)
-pAllow indented first line to differ from rest of paragraph

Examples

Reformat document.txt to default 75 characters wide and output to stdout

fmt < document.txt

Reformat article.txt to 80 characters wide and save to formatted.txt

fmt -w 80 article.txt > formatted.txt

Wrap a long line to the default width

echo 'This is a very long line that needs to be wrapped because it exceeds the default line width' | fmt

Reformat email to 60 characters with uniform spacing between words

fmt -w 60 -u email.txt

Center-justify lines within a 50-character width

fmt -c -w 50 title.txt

Split long lines without joining short lines (preserve existing breaks)

fmt -s input.txt

Reformat and paginate a messy text file for reading

cat messy.txt | fmt -w 72 | less

Format email with preserved quoting indentation

fmt -m -w 80 quoted_email.txt

Related commands