Fundamentals 4 min read

Master the Linux fmt Command: Simple Text Formatting Techniques

This tutorial explains how to use the Linux fmt utility to reformat text, covering basic syntax, line‑width adjustments, first‑line indentation, line splitting, and spacing options with clear examples and command‑line snippets tested on Ubuntu 24.04.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master the Linux fmt Command: Simple Text Formatting Techniques

Introduction

The fmt command is a lightweight Linux utility that automatically formats plain‑text files or standard input, making the output more readable by adjusting line width and paragraph layout. By default it wraps lines at 75 characters, but this can be customized.

Basic Syntax

fmt [-WIDTH] [OPTION]... [FILE]...

The command reads each paragraph from the specified file(s) (or stdin) and outputs the reformatted text to stdout.

Common Options and Examples

Q1: Format a file into a single line

Running fmt without options concatenates the entire file into one continuous line.

fmt filename

Q2: Change the maximum line width

Use -w followed by a number to set a custom line width.

fmt -w 20 filename

Q3: Highlight the first line

The -t option adds a different indentation to the first line, making it stand out.

fmt -t filename

Q4: Split overly long lines

Apply the -s option to break long lines into shorter, more readable segments.

fmt -s filename

Q5: Set word and sentence spacing

With -u, fmt ensures a single space between words and two spaces between sentences, which is enabled by default.

fmt -u filename

Conclusion

Although fmt offers a modest feature set, it remains a powerful tool for quick text reformatting, line‑width control, and consistent paragraph layout. For more advanced usage, consult its manual page.

LinuxCommand LineUnixfmttext 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.