foldx
Wrap each input line to fit in a specified width.
Mirrors GNU fold. Run it as foldx, or as gnux foldx.
Synopsis
foldx [OPTION]... [FILE]...GNU reference
Description
foldx writes each FILE to standard output, breaking any line longer than 80 columns into several. With no FILE, or when FILE is -, it reads standard input. -w WIDTH sets the width; the obsolete form -WIDTH (foldx -72) is accepted too, and whichever is given last wins. Columns are counted as a terminal would: a tab advances to the next multiple of 8, a backspace moves back one column and a carriage return goes back to column 0. -b counts bytes instead, so every byte takes one position. -s breaks a long line after the last blank that fits, rather than exactly at the width, so words are not split unless one is longer than the width. Like GNU fold in the C locale, foldx counts bytes rather than characters, so a multibyte UTF-8 character takes more than one column.
Permissions
Needs read permission on each FILE and search permission on the directories leading to it. Nothing is ever modified.
Use cases
- Wrapping long log lines or generated text to fit a terminal or an email.
- Splitting a long
base64or hex string into fixed-width lines. - Breaking prose at word boundaries with
-s. - Chunking a single-line file into records of a fixed number of bytes with
-b. - Preparing text for a fixed-width display or printer.
Flags
-b, --bytes count bytes rather than columns
--help display this help and exit
-s, --spaces break at spaces
--version output version information and exit
-w, --width WIDTH use WIDTH columns instead of 80Examples
Make a log with very long lines readable in an 80-column terminal
foldx notes.txtFit text into a narrow 40-column display or receipt printer
foldx -w 40 notes.txtWrap a commit message body at 72 columns without breaking words
foldx -s -w 72 essay.txtRun an old script that uses the obsolete width form
foldx -60 notes.txtBreak a one-line key or base64 blob into 64-byte lines
foldx -b -w 64 key.txtWrap the output of another command
catx long.log | foldx -w 100Split a word into one character per line, to count or sort letters
echox abc | foldx -w 1Save a wrapped copy of a draft for an email client that does not wrap
foldx -s -w 72 draft.txt > wrapped.txtWrap several chapter files in one go
foldx -w 72 a.txt b.txtCheck how many screen lines a note will take once wrapped
foldx -w 72 notes.txt | wcx -lPreview a wrapped file in the portable gnux shell, the same on every OS
gnux shell -c 'foldx -s -w 60 notes.txt | headx'Options
Each option has a page of its own, with its usage and examples.
- -b, --bytes: Count bytes rather than columns.
- -s, --spaces: Break at spaces.
- -w, --width: Use WIDTH columns instead of 80.
Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake |
Help in the terminal
foldx --help # options, first examples, exit status
gnux help foldx # this page: the full manual
gnux help foldx --OPTION # one option in depth, with its examples