← All languages
$_
Bash command of the day
Random

fold

Wrap each input line to fit in specified width.

Description

The fold command wraps each line of input to a specified maximum width. By default, it wraps at 80 columns, breaking lines at the exact column boundary.

The -s option makes fold break at spaces rather than in the middle of words, producing more readable output. The -w option sets the maximum line width.

fold is useful for formatting text to fit terminal widths, preparing text for display in narrow columns, and ensuring that files meet line-length requirements.

Arguments

NameDescriptionOptional
file One or more files to fold. Reads from stdin if omitted. Yes
-w Use the specified width instead of the default 80. Yes
-s Break at spaces rather than at the exact column width. Yes

Example

fold -w 40 long_lines.txt
fold -s -w 72 essay.txt
echo 'a very long string...' | fold -w 20