fold flags & options

Basic usage

Wrap lines at 80 characters (default).

fold longlines.txt

-w, --width

Set the wrap width.

fold -w 60 file.txt
fold -w 40 file.txt

-s, --spaces

Break at the last space within the width instead of mid-word.

fold -s -w 72 document.txt

-b, --bytes

Count bytes instead of columns (matters for multibyte characters).

fold -b -w 100 file.txt

Pipe usage

Wrap output from other commands.

cat /var/log/syslog | fold -s -w 120

Combine with fmt

fold wraps at exact width; fmt reflows paragraphs. Use fold -s for simple wrapping.

echo "A very long line of text that should be wrapped at word boundaries for readability" | fold -s -w 40