English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux fmt command

Comprehensive List of Linux Commands

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"-If "fmt" is specified, the fmt command will read data from the standard input device.

Syntax

fmt [-cstu][-p<starting string of the column>][-w<number of characters per column>][--help][--version][File...]

Parameter Description:

  • -c or--crown-margin The first two columns of each paragraph are indented.

  • -p<starting string of the column> or-prefix=<starting string of the column> Only merge columns containing the specified string, usually used in program language annotations.

  • -s or--split-only Split columns with more than the number of characters per column, but do not merge columns with fewer characters than the number of characters per column.

  • -t or--tagged-paragraph The first two columns of each column are indented, but the1columns and the2The indentation format of the columns is different.

  • -u or--uniform-spacing Each character is separated by a space character, and sentences are separated by two space characters.

  • -w<number of characters per column> or--width=<number of characters per column> or-Set the maximum number of characters per column.

  • --help Online help.

  • --version Display version information.

Online Examples

Rewrap the specified file. For example, the file testfile has a total of5 lines of text, which can be reformatted using the command, the command is:

fmt testfile

The output result is as follows:

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

Rewrap the file testfile into85 characters per line, and output 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 rewrap, the output result is as follows:

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

Comprehensive List of Linux Commands