When you dump a massive block of raw, unformatted text into a Linux terminal, the text will often stretch all the way across the screen, breaking awkwardly at the absolute edge of your monitor and making the text incredibly difficult to read. To format a large block of text and force it to cleanly wrap at a highly specific character width, you must use the fold command.
How the fold Command Works
The fold command is a simple GNU text manipulation utility. It reads a file line by line, counts the characters, and forcefully injects a hard line-break (newline character) the exact moment it hits the maximum width threshold.
By default, if you run the command without any flags, it will wrap text at exactly 80 columns (characters).
fold paragraph.txt
The command will output the text to your terminal screen, perfectly constrained to an 80-character column width, making it much easier to read without stretching your eyes across a widescreen monitor.
Setting a Custom Column Width
If you are formatting a file to be read on a very small mobile device, or if you want to create narrow, newspaper-style columns, you can define an exact mathematical width using the -w (width) flag.
To forcefully wrap the text at exactly 40 characters, run:
fold -w 40 paragraph.txt
The output will instantly become a tall, narrow block of text.
Fixing Awkward Word Breaks
The standard fold command is mathematically ruthless. It counts characters, not words. If it hits character number 40 right in the absolute middle of the word “beautiful”, it will aggressively break the word in half (e.g., “beauti” on the first line, “ful” on the second line). This makes the output look highly unprofessional.
To prevent the command from butchering words, you must append the -s (spaces) flag.
fold -s -w 40 paragraph.txt
The -s flag introduces logic to the wrapping algorithm. It instructs fold to monitor the 40-character limit, but if it is in the middle of a word, it will scan backwards and inject the line break at the most recently encountered empty space instead. This ensures that every single word is kept intact, resulting in a perfectly clean, readable block of formatted text.