fold Command
Purpose
Folds long lines for fixed-width output devices.
Syntax
Description
The fold command is a filter that folds long lines for a finite-width output device. By default, the command folds the contents of standard input, breaking the lines to a line width of 80 (eighty). You can also specify one or more files as input to the command. The standard input is used if you do not specify any file parameters or if you specify the '-' parameter.
The fold command inserts a new-line character in the input lines so that each output line is as wide as possible without exceeding the value specified by the Width parameter. If the -b flag is specified, line width is counted in bytes. If the -b flag is not specified:
- Width is counted in columns as determined by the LC_CTYPE environment variable.
- A backspace character decreases the length of an output line by 1.
- A tab character advances to the next column where the column position is 1 plus a multiple of 8.
The fold command accepts -w Width values in multiples of 8 if the file contains tabs. To use other width values when the file contains tabs, use the expand command before using the fold command.
- The fold command may affect any underlining that is present.
- The fold command does not insert new-line characters in the middle of multibyte characters even when the -b flag is used.
Flags
Item | Description |
---|---|
-b | Counts Width in bytes. The default is to count in columns. |
-s | Breaks the line after the rightmost blank within the Width limit, if an output line segment contains any blank characters. The default is to break lines so each output line segment is as wide as possible. |
-w Width | Specifies the maximum line width as the value of the Width variable. The default is 80. |
Parameters
The fold command supports the following parameters:
Item | Description |
---|---|
File | The path name of a text file that must be folded. If you do not specify any file parameters, the standard input is used. |
INPUT FILES | If you specify the -b flag, the input files are text files and the width of the lines
of the text files can exceed {LINE_MAX} bytes in length. Note: If the -b flag is not
specified, the input files are text files and the width of the lines of the text files can not
exceed {LINE_MAX} bytes in length.
|
Exit Status
This command returns the following exit values:
Item | Description |
---|---|
0 | All input files processed successfully. |
>0 | An error occurred. |
Examples
To fold the lines of a file named longlines into width 72 (seventy-two), enter:
fold -w 72 longlines
Files
Item | Description |
---|---|
/usr/bin/fold | Contains the fold command. |