Linux and Unix fold command
Quick links
About fold
Syntax
Examples
Related commands
Linux and Unix main page
Filter for folding lines. This breaks the lines to have a maximum of x width column position (or bytes).
fold [ -bs ] [-w width | -width] [file]
| -b | Count width in bytes rather than column positions. |
| -s | If 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 | -width | Specify 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. |
| file | A path name of a text file to be folded. If no file operands are specified, the standard input will be used. |
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
