fmt(1)
fmt reformats text to a specified line length, wrapping paragraphs and removing extra whitespace.
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
| Flag | What it does |
|---|---|
-w WIDTH | Set maximum line width to WIDTH characters (default 75) |
-c | Center-justify lines instead of left-justifying |
-u | Uniform spacing: one space between words, two after sentences |
-s | Split lines only; do not join short lines |
-t | Test mode; don't actually format, just check validity |
-m | Preserve indentation of first two lines (mail quoting) |
-p | Allow indented first line to differ from rest of paragraph |
Examples
Reformat document.txt to default 75 characters wide and output to stdout
fmt < document.txtReformat article.txt to 80 characters wide and save to formatted.txt
fmt -w 80 article.txt > formatted.txtWrap 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' | fmtReformat email to 60 characters with uniform spacing between words
fmt -w 60 -u email.txtCenter-justify lines within a 50-character width
fmt -c -w 50 title.txtSplit long lines without joining short lines (preserve existing breaks)
fmt -s input.txtReformat and paginate a messy text file for reading
cat messy.txt | fmt -w 72 | lessFormat email with preserved quoting indentation
fmt -m -w 80 quoted_email.txt