Linux and Unix fold command

Quick links

About fold
Syntax
Examples
Related commands
Linux and Unix main page

About fold

Filter for folding lines. This breaks the lines to have a maximum of x width column position (or bytes).

Syntax

fold [ -bs ] [-w width | -width] [file]

-bCount width in bytes rather than column positions.
-sIf a segment of a line contains a blank character within the first width column positions (or bytes), break the line after the last such blank character meeting the width constraints. If there is no blank character meeting the requirements, the -s option will have no effect for that output segment of the input line.
-w width | -widthSpecify the maximum line length, in column positions (or bytes if -b is specified). If width is not a positive decimal number, an error is returned. The default value is 80.
fileA path name of a text file to be folded. If no file operands are specified, the standard input will be used.

Examples

fold -5 myfile.txt > newfile.txt

The above command would fold the lines of myfile.txt to 5 character width and re-route the results to the file newfile.txt

Related commands

cut
pr