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 host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host 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 man Command: Read Command Manual Pages

Linux man Command: Read Command Manual Pages

Learn how to use the Linux man command to find and read command manuals, sections, options, and related pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Administration Memo: Essential Commands and System Checks

Linux Administration Memo: Essential Commands and System Checks

A compact Linux administration reference for checking system information, processes, storage, networking, users, permissions, services, and logs.

Linux nohup Command: Keep a Command Running After Logout

Linux nohup Command: Keep a Command Running After Logout

Learn how to use the Linux nohup command to keep a command running after the terminal closes or the user logs out, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

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 ssh Command: Connect to a Remote Host Securely

Linux ssh Command: Connect to a Remote Host Securely

Learn how to connect to a Remote Host Securely with the Linux ssh command, including practical examples, key options, and important precautions.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

Linux resolvectl Command: Inspect systemd DNS Resolution

Linux resolvectl Command: Inspect systemd DNS Resolution

Learn how to inspect systemd DNS Resolution with the Linux resolvectl command, including practical examples, key options, and important precautions.