How to Use fold Command in Linux

How to Use fold Command in Linux

This guide is about How to Use fold Command in Linux. So read this free guide, How to Use fold Command in Linux step by step. If you have query related to same article you may contact us.

How to Use fold Command in Linux – Guide

On Linux, the fold command wraps each line in an input file to a specified width and sends it to standard output. It wraps rows with a maximum width of 80 columns by default, although this can be changed. Folding input using the fold command requires a file or standard input.

Using the fold command:

$fold GfG.txt

In the example above we passed a text file called GfG to the fold command and as you can see in the output it wraps the line up for 80 columns.

Different bend command options:

  • -w :By using this option in the fold command, we can limit the width by the number of columns. When using this command, we change the column width from the default width of 80. Syntax: $ fold -w GfG.txt

    In the example above, we wrap the lines of GfG.txt to a width of 60 columns.

  • -b : This option of the fold command is used to limit the output width by the number of bytes instead of the number of columns. Using this, we can enforce the output width on the number of bytes. Syntax: $fold -b GfG.txt

    In the example above, we limited the output width of the file to 40 bytes and the command breaks the output to 40 bytes.

  • -s : This option is used to wrap lines at spaces so that words are not broken. If a segment of the line contains a blank character in the first positions of the width column, wrap the line after the last blank character that meets the width constraints. Syntax: $ fold -w -s GfG.txt

    If you compare the example above with the previous one, you will see that the lines only break at spaces, whereas in other examples the output is displayed in such a way that some of the words are broken between the lines.

  • Final note

    I hope you like the guide How to Use fold Command in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.

    We will be happy to hear your thoughts

    Leave a reply

    How to Guides, Best Lists, Top 10 and Tech News - Compsmag
    Logo