FOLD(1) General Commands Manual FOLD(1)

foldbreak lines

fold [-sb] [-w idth] [file]…

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 th 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.

, --spaces
Break after the last blank on a line if possible.
, --bytes
Each character has a width equal to its length in bytes, instead.
, --width=columns
Limit lines to no more than this many columns (bytes if -b). Default: .

if a file couldn't be opened or read.

$ echo '😩ąęćźń' | fold -w4   $ echo '😩ąęćźń' | fold -bw4
😩ąę                          😩
ćźń                           ąę
                              ćź
                              ń

$ cat form
Groceries for February:
    Bananas    3.5kg     $4.51
    Kiwis      2kg       $3.19     Call Siegfried to explain short!
    Bread                $20.21
$ fold -w20 form              $ fold -sw20 form
Groceries 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

paste(1), iswblank(3), mbrtowc(3), wcwidth(3)

Conforms to IEEE Std 1003.1-2008 (“POSIX.1”); specifying -w shorter than any input character is explicitly undefined — this implementation behaves as if each occupied an entire line.

Appeared with a fully-formed baseline semantic in 1BSD as fold(VI):

[ -width ] [ file ... ]
With single-byte unit-width characters, and widths, including a null argument, allowed and inserting extra newlines before each output byte.

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.

December 25, 2022 voreutils pre-v0.0.0-latest