fold [OPTION]... [FILE]...
Wrap input lines in each FILE, writing to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too.
The following command takes the input sentence from stdin and wraps it to a maximum width of 30 characters.
$ echo "This is a long sentence that needs to be wrapped to fit within a certain width." | fold -w 30
This is a long sentence that n
eeds to be wrapped to fit with
in a certain width.
The -s option tells fold
to break lines at spaces instead of arbitrary points, which helps to preserve existing line breaks in the file.
$ echo "This is a long sentence that needs to be wrapped to fit within a certain width." | fold -s -w 30
This is a long sentence that
needs to be wrapped to fit
within a certain width.