| fold | |
|---|---|
| Original author | Bill Joy |
| Initial release | 1977; 49 years ago (1977) |
| Operating system | Unix andUnix-like |
| Platform | Cross-platform |
| Type | Command |
| License | coreutils:GNU GPL v3 |
fold is aUnix command used for making afile with long lines more readable on a limited widthcomputer terminal by performing aline wrap.
MostUnix terminals have a default screen width of 80, and therefore reading files with long lines could get annoying. The fold command puts aline feed every X characters if it does not reach a new line before that point. If the-w argument is set, the fold command allows the user to set the maximum length of a line.
The utility first appeared in1BSD of 1977 and was originally written byBill Joy.[1][2]
fold is part of theX/Open Portability Guide since issue 4 of 1992. It was inherited into the first version of POSIX.1 and theSingle Unix Specification.[3]
The version offold bundled inGNUcoreutils was written by David MacKenzie.[4]
The command is available as a separate package forMicrosoft Windows as part of theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[5]
As a usage example, to fold a file namedfile.txt to have a maximum of 50 characters per line, one could run the following command:
$catfile.txtLorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissimvenenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non,purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornaredictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,ornare in, posuere eget, pede.Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauristellus, sollicitudin non, semper eget, sodales non, pede. Phasellus variusullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipitvel, tortor. Cras varius.Nullam fringilla pellentesque orci. Nulla eu ante pulvinar velit rhoncuslacinia. Morbi fringilla lacus quis arcu. Vestibulum sem quam, dapibus in,fringilla ut, venenatis ut, neque.$fold-w50file.txtLorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissimvenenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non,purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornaredictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et,ornare in, posuere eget, pede.Vivamus rhoncus. Quisque lacus. In hac habitasse platea dictumst. Nullam mauristellus, sollicitudin non, semper eget, sodales non, pede. Phasellus variusullamcorper libero. Fusce ipsum lorem, iaculis nec, vulputate vitae, suscipitvel, tortor. Cras varius.Nullam fringilla pellentesque orci. Nulla eu antepulvinar velit rhoncuslacinia. Morbi fringilla lacus quis arcu. Vestibulum sem quam, dapibus in,fringilla ut, venenatis ut, neque.
fold(1) – FreeBSD General CommandsManualprintf – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group