NAME
fold —
break lines
SYNOPSIS
fold |
[-sb] [-w
idth] [file]… |
DESCRIPTION
Breaks lines from files (standard input
stream if "-", the default) such that they do
not go past the -wth column (byte if
-b), into to the standard output stream.
Unless -b, tabs are stopped every
8th column, backspaces
rewind by one column, and carriage returns rewind to the first column.
Multi-byte character sequences, according to the current locale, are never interrupted; invalid ones are taken to have null width.
OPTIONS
-s,--spaces- Break after the last blank on a line if possible.
-b,--bytes- Each character has a width equal to its length in bytes, instead.
-w,--width=columns- Limit lines to no more than this many columns (bytes if
-b). Default: 80.
EXIT STATUS
1 if a file couldn't be opened or read.
EXAMPLES
$echo'😩ąęćźń'|fold-w4$echo'😩ąęćźń'|fold-bw4 😩ąę 😩 ćźń ąę ćź ń
$catformGroceries for February: Bananas 3.5kg $4.51 Kiwis 2kg $3.19 Call Siegfried to explain short! Bread $20.21$fold-w20form$fold-sw20formGroceries for Februa Groceries for ry: February: Bananas 3.5kg Bananas $4.51 3.5kg $4.51 Kiwis 2kg Kiwis 2kg $3.19 Call $3.19 Call Siegfried to explain Siegfried to short! explain short! Bread Bread $20.21 $20.21
SEE ALSO
STANDARDS
Conforms to IEEE Std 1003.1-2024
(“POSIX.1”); specifying -w shorter
than any input character is explicitly undefined — this
implementation behaves as if each occupied an entire line.
HISTORY
Appeared with a fully-formed baseline semantic in 1BSD as fold(VI):
4.3BSD-Reno sees present-day
-w width in addition to the
legacy -width format, scrubbed
from documentation.
The 1BSD version is included (but,
seemingly, unused) as part of the vi distribution in
AT&T System III UNIX et al.;
AT&T System V Release 4 UNIX
copies it as an installed command with an update to also handle
-w.
IEEE Std 1003.2-1992
(“POSIX.2”) specifies locale behaviour and creates
-sb, as present-day.