fold
Text processing
Usage
fold -w 80 [file]Hard-wraps long lines at a fixed width by inserting real newlines; without -s it cuts words in half, and unlike a terminal's soft wrap it changes the file itself.
Common flags
| Flag | Meaning |
|---|---|
| -w | Wrap at this width; the default is 80 |
| -s | Break at spaces instead of mid-word |
| -b | Count bytes rather than display columns |
Examples
fold -w 72 -s letter.txtWraps prose at 72 columns on word boundaries.
fold -w 1 word.txtOne character per line.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does fold do?
Hard-wraps long lines at a fixed width by inserting real newlines; without -s it cuts words in half, and unlike a terminal's soft wrap it changes the file itself.
Q. How do I type it?
fold -w 80 [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
3 are listed here; the full set is in man fold. This command sits under Text processing.
Related commands
man page: man fold