Linux系统中的fmt命令主要用于文本
内容的格式调整。
该命令会从给定的文件中读取内容,按照指定的格式重新整理后输出到标准输出。如果提供的文件名是"-",则表示从标准输入获取数据进行处理。
fmt [-cstu][-p][-w][--help][--version][文件...]
参数说明:
对testfile文件进行格式重排操作。假设该文件包含5行内容,可以执行以下命令:
fmt testfile
输出效果如下:
$ fmt testfile #对testfile 文件进行重排 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux
若希望将testfile文件按每行最多85字符进行重排,并显示在终端上,可使用:
fmt -w 85 testfile
首先查看原文件内容:
$ cat testfile #查看testfile 文件的内容 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux
执行格式化后结果为:
$ fmt -w 85 testfile #设置每行最大宽度为85字符 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux Linux