Linux fmt Command: Reformat Plain-Text Paragraphs
fmt outputs general text paragraphs in a reflowed, easy-to-read format. It can be used to tidy up notes or drafts where line breaks are inconsistent.
What is the fmt command?
Since it is a tool for rearranging paragraphs, it is not suitable for source code, CSV, Markdown tables, or logs that have meaningful line boundaries. The original file is basically not modified, and the adjusted text is output.
Basic syntax
fmt [options] [file...]
Installed implementations and options may vary depending on the distribution. Check the description on your current system with man fmt.
Examples
Basic paragraph formatting
Rearranges the lines of input paragraphs into a normal reading width.
fmt notes.txt
Specifying line width
Wraps paragraphs again targeting about 60 columns.
fmt -w 60 draft.txt
Save output separately
Keeps the original and saves the result in a new file.
fmt -w 72 draft.txt > draft-formatted.txt
Understanding the Result of Refolding Paragraphs
fmt does not simply cut at a specified width, it rearranges the words within the paragraph. The example below converts a long single line into multiple lines around 20 characters wide.
printf 'one two three four five six\n' | fmt -w 20
Example output (word arrangement may vary depending on implementation and options):
one two three four five six
fmt is not a tool that forcibly cuts words in the middle. To split character positions at a fixed width, use fold. For text where space structure is important, such as code, tables, or indentation, you should check the results in advance before applying paragraph rearrangement.
Main Options and Format
| Options/Format | Description |
|---|---|
-w N |
Set the target line width to N columns. |
-s |
Only split long lines, without merging short lines. |
-u |
Adjust the spacing between words evenly. |
-p prefix |
Only target lines with the specified prefix. |
Precautions when using
fmt does not understand the meaning of formatting, so documents with list indentation, code blocks, or quotations should be reviewed. The character width may differ from what is visible on the screen, so check Korean and wide character input as well.
Frequently Asked Questions
Does fmt modify the original file?
No. By default, it outputs the result to standard output. Save it to a separate file and check it.
Official Documentation
You can check the exact behavior of the options and the differences between implementations in the official fmt documentation.









