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.

More in This Category
Linux xz Command: Compress a File in xz Format

Linux xz Command: Compress a File in xz Format

Learn how to compress a File in xz Format with the Linux xz command, including practical examples, key options, and important precautions.

Linux reboot Command: Restart the System Safely

Linux reboot Command: Restart the System Safely

Learn how to restart the System Safely with the Linux reboot command, including practical examples, key options, and important precautions.

Linux hostnamectl Command: Show and Change the Host Name

Linux hostnamectl Command: Show and Change the Host Name

Learn how to show and Change the Host Name with the Linux hostnamectl command, including practical examples, key options, and important precautions.

Linux command Command: Run Commands While Bypassing Aliases and Functions

Linux command Command: Run Commands While Bypassing Aliases and Functions

Learn how to use the Linux command command to check command availability and bypass shell aliases or functions, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Linux Tutorial / How the Shell Runs Commands: ;, &&, ||, Aliases, and Environment Variables

Learn how Bash resolves commands and uses exit status with ;, &&, and ||, then distinguish aliases, shell variables, and exported environment variables.

Linux unalias Command: Remove Command Aliases

Linux unalias Command: Remove Command Aliases

Learn how to use the Linux unalias command to remove one or all aliases from the current shell session, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux shred Command: Overwrite File Data and Understand Its Limits

Linux shred Command: Overwrite File Data and Understand Its Limits

Learn how Linux shred overwrites file data, which options control its passes and removal, and why SSDs, snapshots, backups, and modern filesystems limit its guarantees.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux zypper Command: Manage Packages on openSUSE and SUSE

Linux zypper Command: Manage Packages on openSUSE and SUSE

Learn how to manage Packages on openSUSE and SUSE with the Linux zypper command, including practical examples, key options, and important precautions.

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Practice creating, copying, renaming, moving, and deleting files and directories in a dedicated folder while checking each result safely.