Discuss the basic usage of fmt and some of the main features it provides

Sometimes you will find that you need to format the contents of a text file. For example, the text file has one word per line, and the task is to put all the words on the same line. Of course, you can do it by hand, but no one likes to do such time-consuming work by hand. Moreover, this is just an example – the actual task may be strange.

Fortunately, there is a command that can satisfy at least part of the text formatting needs. This tool is fmt. This tutorial will discuss the basic usage of fmt and some of the main features it provides. All commands and instructions in the text have been tested under Ubuntu 16.04LTS.

Linux fmt command

The fmt command is a simple text formatting tool that anyone can run from the command line. Its basic syntax is:

Fmt [-WIDTH] [OPTION]... [FILE]...

Its man page says so:

Reformat each paragraph in the file and write the result to standard output. The option -WIDTH is an abbreviation of the form --width=DIGITS.

The following examples of question and answer should give you a good understanding of the usage of fmt.

Q1, how to use fmt to format text content into the same line?

This can be done using the basic form of the fmt command (omitting any options). You just need to pass the filename as a parameter to it.

Fmt [file-name]

The screenshot below is the result of the execution of the command:

You can see that multiple lines of content in the file are formatted into the same line. Please note that this does not modify the original file (file1).

Q2, how to modify the maximum line width?

By default, the maximum line width in the output produced by the fmt command is 75. However, if you want, you can modify it with the -w option, which accepts a number representing the new line width as a parameter value.

Fmt -w [n] [file-name]

The following example cuts the line width to 20:

Q3, how to make fmt highlight the first line?

This is done by making the indentation of the first line different, which you can do with the -t option.

Fmt -t [file-name]

Q4, how to split long lines using fmt?

The fmt command can also be used to split long lines. You can apply this function with the -s option.

Fmt -s [file-name]

Below is an example:

Q5. How do you separate spaces between words and words?

The fmt command provides a -u option, which separates words and words with a single space, separated by two spaces. You can use it like this:

Fmt -u [file-name]

Note that in our case, this feature is enabled by default.

to sum up

That's right, fmt doesn't provide much functionality, but it doesn't mean it's not widely used. Because you never know when you will use it. In this tutorial, we have covered the main options provided by fmt. For more details, check out the man page for the tool.

Portable Power Stations

We are dedicated charging solution Manufacturer since 2005.



Supply various Power Station including Portable Power Stations, Solar Power Generators, Smallest Generator etc.


Manufacturing high quality products for customers according to international standards, such as CE ROHS FCC REACH UL SGS BQB etc.


To constantly offer clients more innovative products and better services is our consistent pursuit.




portable power stations for camping, solar pow er stations, jackery portable power station

TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.itopnoobluetoothes.com