fold Command on Linux: Wrap Long Lines to a Fixed Width

fold command linux - custom-fold-featured.png

fold on Linux hard-wraps lines at a character width — useful when pasting log excerpts into tickets, emails, or narrow terminals without scrolling sideways.

Pair with: head & tail,
grep,
column.

Fixed width

Default is 80 columns — override with -w.

bashwidth
fold -w 72 long-lines.txt | head
fold -w
width

Break at spaces

-s tries not to split words when possible.

bashspaces
fold -s -w 60 /var/log/syslog | head
fold -s
spaces

Pipelines

Wrap after extracting lines with grep.

bashpipe
grep ERROR huge.log | fold -s -w 100 | less
grep
pipe

Not markdown

fold is plain text — use prettier tools for HTML or Markdown rendering.

TipFor wide tables, column -t often reads better than fold.
plain
text

Quick Reference

  • fold -w 80 file
  • Word-friendly: fold -s -w 72 file
  • Often piped after grep

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.