fmt command in linux with example

In this tutorial, I use fmt command to format a file, set the column with, and format uniform spaces. Now, let’s go fmt command in Linux for example.

What does fmt mean?

fmt – simple optimal text formatter

Syntax

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

In man page the describe it

  • fmt – simple optimal text formatter.
  • man fmt – More details information about fmt command.
fmt command in linux with example

fmt command in linux with example

By default, fmt sets the column width at 75.

I have created a file fmt_command.txt

[vagrant@DevopsRoles ~]$ cat fmt_command.txt 
 HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.
 Devops Roles.
 Hello world. xxx.

fmt with no options

[vagrant@DevopsRoles ~]$ fmt fmt_command.txt 
HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.  Devops Roles.

Hello world. xxx.

How to change the width of formatting.

[vagrant@DevopsRoles ~]$ fmt --width 20 fmt_command.txt 
 HuuPV, My website
 DevopsRoles.com and
 HuuPhan.com.SN:199x.
 Devops Roles.
 Hello world. xxx.

with -u option uses one space between words and two spaces after sentences for formatting.

[vagrant@DevopsRoles ~]$ fmt -u fmt_command.txt 
 HuuPV, My website DevopsRoles.com and HuuPhan.com.SN:199x.  Devops Roles.
 Hello world. xxx.

Conclusion

fmt command is a simple command in Linux. It is used to format a file, set the column with, and format uniform spaces. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.