fmt
Quick Reference
Command Name:
fmt
Category:
text processing
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Text formatting
Format text data for optimal readability
- 2
Report generation
Generate reports with optimal line wrapping
- 3
Scripting
Use in shell scripts to format text data programmatically
- 4
Text processing
Manipulate text data in pipelines and scripts
Syntax
fmt [OPTION]... [FILE]...
Options
Option | Description |
---|---|
-c, --crown-margin | Preserve indentation of first two lines in each paragraph |
-p PREFIX, --prefix=PREFIX | Only reformat lines beginning with PREFIX, reattaching PREFIX to reformatted lines |
-s, --split-only | Split long lines but don't refill (reformat) paragraphs |
-t, --tagged-paragraph | Indentation of first line different from second line |
-u, --uniform-spacing | One space between words, two after sentences |
-w WIDTH, --width=WIDTH | Set maximum line width to WIDTH (default 75 characters) |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the fmt
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
fmt filename.txt
Format the text in the file with default settings, wrapping lines to 75 characters and preserving paragraph breaks. The result is displayed on standard output.
fmt -w 60 filename.txt
Format the text with a line width of 60 characters instead of the default 75. This is useful when preparing text for narrower displays or specific layout requirements.
fmt -w 60 filename.txt > formatted.txt
Format the text with a width of 60 characters and save the result to a new file instead of displaying it on screen.
cat filename.txt | fmt -w 80
Read input from a pipe instead of a file, format it with a width of 80 characters. This demonstrates how fmt can work within command pipelines.
Advanced Examples:
fmt -s filename.txt
Split long lines but don't refill paragraphs. This preserves the original paragraph structure while ensuring no line exceeds the width limit.
fmt -u filename.txt
Use uniform spacing (one space between words, two after sentences). This produces more consistent, typographically correct text formatting.