Fundamentals 5 min read

Master Linux fmt: Format Text, Adjust Width, and Highlight Lines

This tutorial explains the Linux fmt command, covering its default behavior, how to change line width, highlight the first line, split long lines, and control spacing, with clear examples and command syntax tested on Ubuntu 24.04.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux fmt: Format Text, Adjust Width, and Highlight Lines

The fmt command is a simple yet powerful Linux utility for reformatting plain‑text files, making paragraphs tidy and improving readability. By default it wraps lines to 75 characters, but you can customize the width and other formatting options.

Basic Usage

The general syntax is: fmt [-WIDTH] [OPTION]... [FILE]... It reads each paragraph, reformats it, and writes the result to standard output. The -WIDTH option lets you set a specific line width.

Q1: How to format a file into a single line?

Running fmt without options collapses the entire file into one continuous line: fmt filename The original file remains unchanged.

Q2: How to change the maximum line width?

Use the -w option followed by a number to set a custom width, e.g., 20 characters:

fmt -w 20 filename

Q3: How to highlight the first line?

Apply the -t option to give the first line a different indentation, making it stand out:

fmt -t filename

Q4: How to split overly long lines?

The -s option forces fmt to break lines that exceed the specified width, improving paragraph structure:

fmt -s filename

Q5: How to set word and sentence spacing?

With the -u option, fmt inserts a single space between words and two spaces between sentences, which is enabled by default:

fmt -u filename

Summary

Although fmt offers a modest feature set, it remains an effective tool for quick text reformatting, line‑width adjustment, and consistent typography. For more advanced options, consult the manual page.

Linuxfmttext formatting
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.