fold long lines for finite width output
fold is a filter which folds the contents
of the specified files, or the standard input if no files are specified,
breaking the lines to have a maximum of 80 display columns.
The options are as follows:
- Count width in bytes rather than column positions.
- If an output line would be broken after a non-blank character but contains at least one blank character, break the line earlier, after the last blank character. This is useful to avoid line breaks in the middle of words, if possible.
- Specifies a line width to use instead of the default of 80.
-b is specified, a backspace
character decrements the column position by one, a carriage return resets
the column position to zero, and a tab advances the column position to the
next multiple of eight.
- The character encoding locale(1). It decides which byte sequences form characters and what their display width is. If unset or set to "C", "POSIX", or an unsupported value, each byte except backspace, tab, newline, and carriage return is treated as a character of display width 1.
fold utility exits 0 on
success, and >0 if an error occurs.
fold utility is compliant with the
IEEE Std 1003.1-2008 (“POSIX.1”)
fold utility first appeared in
1BSD. It was rewritten for
4.3BSD-Reno to improve speed and modernize style.
-s options were
added to NetBSD 1.0 for IEEE Std
1003.2 (“POSIX.2”) compliance.
Bill Joy wrote the original version of
fold on June 28, 1977. Kevin
Ruddy rewrote the command in 1990, and J. T.
Conklin added the missing options in 1993.
Traditional roff(7) output semantics, implemented both by GNU nroff and by
only uses a single backspace for backing up the previous character, even for
double-width characters. The
semantics required by POSIX mishandles such backspace-encoded sequences,
breaking lines early. The fmt(1) utility provides similar functionality and does not
suffer from that problem, but isn't standardized by POSIX.