Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux fmt Command

Linux fmt Command

Linux Command Reference Linux Command Reference

The Linux fmt command is used to format text files.

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

Syntax

fmt [-cstu][-p<列起始字符串>][-w<每列字符数>][--help][--version][文件...]

Parameter Description:

Example

Reformat the specified file. If the file testfile has 5 lines of text, you can reformat it with the following command:



fmt testfile 

The output is as follows:



$ fmt testfile #重排testfile 文件  

hello Linux! Linux is a free Unix-type operating system. This is a  

Linux testfile! Linux Linux 

To reformat testfile to 85 characters per line and output it to standard output, the command should be:



fmt -w 85 testfile

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



$ cat testfile #查看testfile 文件的内容  

hello Linux!  

Linux is a free Unix-type operating system.  

This is a Linux testfile!  

Linux  

Linux 

After reformatting with the fmt command, the output is as follows:



$ fmt -w 85 testfile #指定重排宽度为85个字符  

hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile!  

Linux Linux 

Linux Command Reference Linux Command Reference