Easy Tutorial
❮ Linux Comm Sndconfig Linux Comm Userconf ❯

Linux fmt Command

Linux Command Manual

The Linux fmt command is used to format text files.

The fmt command reads content from the specified file, rearranges it according to the specified format, and outputs it to the standard output device. If the specified file name is "-", the fmt command will read data from the standard input device.

Syntax

fmt [-cstu][-p<column start string>][-w<number of characters per line>][--help][--version][file...]

Parameter Description:

Example

Rearrange the specified file. For example, if the file testfile contains 5 lines of text, you can rearrange the format of the file with the command:

fmt testfile

The output is as follows:

$ fmt testfile # Rearrange the testfile file
hello Linux! Linux is a free Unix-type operating system. This is a
Linux testfile! Linux Linux

To rearrange the file testfile into 85 characters per line and output it to the standard output device, the command should be:

fmt -w 85 testfile

For comparison, first use the cat command to view the file content:

$ cat testfile # View the content of the testfile file
hello Linux!
Linux is a free Unix-type operating system.
This is a Linux testfile!
Linux
Linux

After using the fmt command to rearrange, the output is as follows:

$ fmt -w 85 testfile # Specify the rearrangement width as 85 characters
hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!
Linux Linux

Linux Command Manual

❮ Linux Comm Sndconfig Linux Comm Userconf ❯