fmt
Format text to fit specified width
TLDR
Reformat a file
Reformat a file producing output lines of (at most) n characters
Reformat a file without joining lines shorter than the given width together
Reformat a file with uniform spacing (1 space between words and 2 spaces between paragraphs)
SYNOPSIS
fmt [OPTION]... [FILE]...
PARAMETERS
-w WIDTH, --width=WIDTH
Sets the maximum line width for the output. Lines will be wrapped to this width. The default width is usually 75 characters.
-WIDTH
A shorthand for -w WIDTH. For example, -72 sets the width to 72 characters.
-c, --crown-margin
Preserves the indentation of the first two lines of a paragraph, but reflows subsequent lines to match the second line's indentation.
-p PREFIX, --prefix=PREFIX
Reformat only lines that begin with PREFIX, preserving the prefix and its indentation. Other lines are passed through unchanged.
-s, --split-only
Splits long lines that exceed the target width, but does not reflow shorter lines or combine lines to fill space. Useful for simple line breaking without full reformatting.
-t, --tagged-paragraph
Treats the first line of a paragraph as a tag. Subsequent lines are indented to align with the first non-whitespace character of the first line.
-u, --uniform-spacing
Uses uniform spacing: one space between words, and two spaces between sentences (after a period, question mark, or exclamation point followed by a space).
--help
Displays a help message and exits.
--version
Displays version information and exits.
DESCRIPTION
The fmt command is a straightforward utility used to format plain text files or standard input. Its primary function is to reflow text paragraphs to fit a specified maximum line width. It automatically breaks lines, preserving blank lines and initial indentation as paragraph separators. This makes it ideal for cleaning up emails, code comments, or general plain text documents where consistent line length is desired. By default, fmt attempts to produce output that is easy to read, handling word breaks and spacing intelligently. It reads input from files provided as arguments or from standard input if no files are specified, and writes the formatted output to standard output.
CAVEATS
fmt is a simple text formatter and has certain limitations. It treats blank lines as strict paragraph separators, which might not be desirable for all document types (e.g., source code). It lacks advanced features found in word processors, such as handling tables, lists, or complex nested structures. Using options like --prefix or --tagged-paragraph requires careful consideration to avoid unintended formatting of content that doesn't strictly adhere to the expected pattern. For very complex or structured documents, more powerful text processing tools or dedicated markup languages might be more appropriate.
PARAGRAPH DEFINITION
fmt defines a paragraph as a sequence of non-blank lines separated by one or more blank lines. Each paragraph is formatted independently.
INPUT AND OUTPUT
If no FILE arguments are given, fmt reads from standard input and writes to standard output. If FILEs are provided, it processes each file sequentially. Output is always written to standard output, making it suitable for piping with other commands.
HISTORY
The fmt command is a venerable utility that has been a standard part of Unix-like operating systems for decades. It originated in early Unix versions, with its core functionality of simple paragraph reflowing remaining largely consistent. In the GNU ecosystem, it is part of the GNU Core Utilities (coreutils) package, which provides essential command-line tools. Its development within coreutils focuses on maintaining compatibility, robustness, and performance across various Linux distributions, ensuring its continued relevance for basic text manipulation tasks.