Category

Linux Command


Usage

fold [OPTION]... [FILE]...


Manual

Wrap input lines in each FILE, writing to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too.

Options

  • -b, --bytes: count bytes rather than columns
  • -c, --characters: count characters rather than columns
  • -s, --spaces: break at spaces
  • -w, --width=WIDTH: use WIDTH columns instead of 80
  • --help: display this help and exit
  • --version: output version information and exit

Examples

Fold long contents

The following command takes the input sentence from stdin and wraps it to a maximum width of 30 characters.

$ echo "This is a long sentence that needs to be wrapped to fit within a certain width." | fold -w 30

This is a long sentence that n
eeds to be wrapped to fit with
in a certain width.
Preserve Existing Word Breaks

The -s option tells fold to break lines at spaces instead of arbitrary points, which helps to preserve existing line breaks in the file.

$ echo "This is a long sentence that needs to be wrapped to fit within a certain width." | fold -s -w 30

This is a long sentence that
needs to be wrapped to fit
within a certain width.
 


Share your experience or ask a question