How to Run Fold Command on Linux

Linux is the most preferred open-source OS used to receive various requests from multiple applications and transfers these to the system’s hardware. Linux “fold” command provides your system with better healing abilities. The fold command includes symbols, letters, numbers, and whitespace. The Linux based command use linefeed as a newline character. It contains the value 0*0 under ten decimals and having a hexadecimal format.

Pursue these instructions if you wish to run Fold command on Linux:

Using Folds In the First Step

The lines may seem very lengthy while using fold command. This command contains a paragraph that is folded into small terminals. It might pack multiple terminal windows and provide features to compress these sentences. If we talk about the long extract of Moby Dick, then you can compress it into a compressed format on Linux.


  • In the above fold command, the less is the compressed character for Moby Dick’s text which holds a lengthy paragraph with newline characters.  Similarly, we can see another edition of the same file having short lines:

‘less short-_lines-_moby-dick.txt.”

  • If we expand this command, then we will find that the lines of Moby Dick’s extract are much shorter than the previous one. Every line is terminated through newline letters.

In case, we apply the “hex-dump” command, we will find the byte value inside the file, and we can look for newline characters. The option “-c” (canonical) displays the output to display various hexadecimal values inside the primary body of the screen having text proportions at the side panel in columns. The command of hex-dump is:

“hex-dump-C short-_lines-moby-_dick.txt | less.”

  • In case, you wish to go through the search command of “less,” then it is recommended to tap on succeeding slash tab “/.”
  • Then, enter the keyword “0a” and then hit the “Enter” key. After that, you will see newline characters that will be displayed inside the text. For checking where they are appearing, you may scroll your screen. You can also scroll sideways of your page by using the right and left arrow keys.
  • It can be a limitation to have a newline character present at the finishing point of every line. There is no matter what Windows or applications show this text. There is a problem with both short and long lines as lines don’t adapt to Windows according to the width and display orientation. The length of lines might be excreted through newline characters.

Deducting Long Lines

There is another option in the folding path that describes the maximum width for a particular text section. If we have a content of Moby Dick that has fifty long characters, we can compress it by this command:

“fold -w 50_moby-dick._txt”

Note: The text of Moby Dick’s content will appear in a terminal window having fresh file orientation length. In this case, the actual file won’t modify. It’s only the fold’s output of the extracted paragraph.

Diverting Lines in Spaces

While using fold command, we have to ensure to make arrangements so that the lines split on particular space letters. Also that no words are diverted across two different lines.

“fold -w_50 -s_moby-_dick.txt”

 In this extracted passage of Dick, we can see that the whole paragraph is comfortable to read besides the ragged margin. All the words end the lines where they start.