Wrap each input line to fit in specified width with fold
May 13, 2019
Are you tired of using tools like less
and reading text like this?
Reducing the environmental impact of a smartphone is one o
f our key business goals. For us, that starts by extending
the lifespan of our phone at the first stage of its lifec
ycle. For example, we use modular design to make repairs a
nd upgrades easy for the first user.
With fold
you could be reading it like this:
Reducing the environmental impact of a smartphone is
one of our key business goals. For us, that starts by
extending the lifespan of our phone at the first stage
of its lifecycle. For example, we use modular design
to make repairs and upgrades easy for the first user.
The two examples above are part of the output from this command (with only less
and then with less
and fold
):
$ html2text.py https://www.fairphone.com/en/2019/04/16/refurbished-phones-give-valuable-resources-a-new-life/ | fold -s -w 55 | less
Installation
The tool fold
comes with the GNU core utillities so it’s actually a tool that most should have by default. If you for some reason don’t have it installed, the package should be named coreutils
in all major distros.
Usage
Using it is simple, you can use it by itself:
$ fold <file>
Or use it in combination with other tools like I did:
$ cat <file> | fold
Flags
It only comes with three flags:
-b , --bytes |
Count bytes rather than columns. |
-s , --spaces |
Break at spaces. |
-w , --width=<WIDTH> |
Use |