fold command

The fold command is used to limit the width of file columns. It reads content from the specified file, adds newline characters to columns that exceed the specified width, and then outputs the content to the standard output device. If no file name is specified or if the given file name is -, the fold command will read data from the standard input device.

Syntax

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

Options

  • -b, --bytes: Count bytes instead of columns.
  • -s, --spaces: Break at spaces.
  • -w, --width=WIDTH: Use n columns instead of the default value of 80.
  • --help: Display help information.
  • --version: Display version information.

Examples

Using the fold command to wrap lines with a default maximum width of 80 characters.

fold file.txt
# fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns but this is configurable. To fold input using the fold command, pass a file or standard input to the command.

Using the fold command to wrap lines with a specified maximum width of 50 characters.

fold -w 50 file.txt
# fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns but this is configurable. To fold input using the fold command, pass a file or standard input to the command.

Using the fold command to wrap lines and using the -s option to break lines at spaces to avoid breaking words.

fold -w 50 -s file.txt
# fold command in Linux wraps each line in an input file to fit a specified width and prints it to the standard output. By default, it wraps lines at a maximum width of 80 columns but this is configurable. To fold input using the fold command, pass a file or standard input to the command.

Daily Question

https://github.com/WindrunnerMax/EveryDay

References

https://www.computerhope.com/unix/ufold.htm https://www.runoob.com/linux/linux-comm-fold.html https://www.geeksforgeeks.org/fold-command-in-linux-with-examples/