1FOLD(1P)                   POSIX Programmer's Manual                  FOLD(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fold — filter for folding lines
13

SYNOPSIS

15       fold [-bs] [-w width] [file...]
16

DESCRIPTION

18       The fold utility is a filter that  shall  fold  lines  from  its  input
19       files,  breaking  the lines to have a maximum of width column positions
20       (or bytes, if the -b option is specified). Lines shall be broken by the
21       insertion  of a <newline> such that each output line (referred to later
22       in this section as a segment) is the maximum width possible  that  does
23       not  exceed the specified number of column positions (or bytes). A line
24       shall not be broken in the middle of a character. The behavior is unde‐
25       fined  if width is less than the number of columns any single character
26       in the input would occupy.
27
28       If the <carriage-return>, <backspace>, or <tab> characters are  encoun‐
29       tered  in  the input, and the -b option is not specified, they shall be
30       treated specially:
31
32       <backspace>
33                 The current count of line width shall be decremented by  one,
34                 although  the  count  never  shall  become negative. The fold
35                 utility shall not insert a <newline>  immediately  before  or
36                 after  any  <backspace>, unless the following character has a
37                 width greater than 1 and would cause the line width to exceed
38                 width.
39
40       <carriage-return>
41                 The  current  count  of  line width shall be set to zero. The
42                 fold utility shall not insert a <newline> immediately  before
43                 or after any <carriage-return>.
44
45       <tab>     Each  <tab>  encountered  shall  advance  the column position
46                 pointer to the next tab stop. Tab stops shall be at each col‐
47                 umn position n such that n modulo 8 equals 1.
48

OPTIONS

50       The  fold  utility  shall  conform  to  the  Base Definitions volume of
51       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
52
53       The following options shall be supported:
54
55       -b        Count width in bytes rather than column positions.
56
57       -s        If a segment of a line contains a <blank>  within  the  first
58                 width  column  positions (or bytes), break the line after the
59                 last such <blank> meeting the width constraints. If there  is
60                 no <blank> meeting the requirements, the -s option shall have
61                 no effect for that output segment of the input line.
62
63       -w width  Specify the maximum line  length,  in  column  positions  (or
64                 bytes  if  -b  is  specified). The results are unspecified if
65                 width is not a positive decimal  number.  The  default  value
66                 shall be 80.
67

OPERANDS

69       The following operand shall be supported:
70
71       file      A  pathname  of a text file to be folded. If no file operands
72                 are specified, the standard input shall be used.
73

STDIN

75       The standard input shall be used if no file operands are specified, and
76       shall  be  used  if a file operand is '-' and the implementation treats
77       the '-' as meaning standard input.  Otherwise, the standard input shall
78       not be used.  See the INPUT FILES section.
79

INPUT FILES

81       If  the  -b  option  is  specified, the input files shall be text files
82       except that the lines are not limited to {LINE_MAX} bytes in length. If
83       the -b option is not specified, the input files shall be text files.
84

ENVIRONMENT VARIABLES

86       The following environment variables shall affect the execution of fold:
87
88       LANG      Provide  a  default  value for the internationalization vari‐
89                 ables that are unset or null. (See the Base Definitions  vol‐
90                 ume  of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
91                 ables for the precedence  of  internationalization  variables
92                 used to determine the values of locale categories.)
93
94       LC_ALL    If  set  to  a non-empty string value, override the values of
95                 all the other internationalization variables.
96
97       LC_CTYPE  Determine the locale for the interpretation of  sequences  of
98                 bytes of text data as characters (for example, single-byte as
99                 opposed to  multi-byte  characters  in  arguments  and  input
100                 files),  and  for  the  determination  of the width in column
101                 positions each character would  occupy  on  a  constant-width
102                 font output device.
103
104       LC_MESSAGES
105                 Determine the locale that should be used to affect the format
106                 and contents  of  diagnostic  messages  written  to  standard
107                 error.
108
109       NLSPATH   Determine the location of message catalogs for the processing
110                 of LC_MESSAGES.
111

ASYNCHRONOUS EVENTS

113       Default.
114

STDOUT

116       The standard output shall be a file containing a sequence of characters
117       whose  order  shall  be  preserved  from the input files, possibly with
118       inserted <newline> characters.
119

STDERR

121       The standard error shall be used only for diagnostic messages.
122

OUTPUT FILES

124       None.
125

EXTENDED DESCRIPTION

127       None.
128

EXIT STATUS

130       The following exit values shall be returned:
131
132        0    All input files were processed successfully.
133
134       >0    An error occurred.
135

CONSEQUENCES OF ERRORS

137       Default.
138
139       The following sections are informative.
140

APPLICATION USAGE

142       The cut and fold utilities can be used to  create  text  files  out  of
143       files  with arbitrary line lengths. The cut utility should be used when
144       the number of lines (or records) needs to  remain  constant.  The  fold
145       utility  should be used when the contents of long lines need to be kept
146       contiguous.
147
148       The fold utility is frequently used to send text files to printers that
149       truncate,  rather  than  fold,  lines wider than the printer is able to
150       print (usually 80 or 132 column positions).
151

EXAMPLES

153       An example invocation that submits a file of possibly long lines to the
154       printer (under the assumption that the user knows the line width of the
155       printer to be assigned by lp):
156
157
158           fold -w 132 bigfile | lp
159

RATIONALE

161       Although terminal input in canonical processing mode requires the erase
162       character (frequently set to <backspace>) to erase the previous charac‐
163       ter (not byte or column position), terminal output is not buffered  and
164       is  extremely  difficult,  if  not  impossible, to parse correctly; the
165       interpretation depends entirely on the physical  device  that  actually
166       displays/prints/stores  the  output.  In  all  known  internationalized
167       implementations, the utilities producing output for mixed  column-width
168       output assume that a <backspace> character backs up one column position
169       and outputs enough <backspace> characters to return to the start of the
170       character  when  <backspace>  is  used to provide local line motions to
171       support underlining and emboldening operations. Since fold without  the
172       -b option is dealing with these same constraints, <backspace> is always
173       treated as backing up one column position rather than  backing  up  one
174       character.
175
176       Historical  versions of the fold utility assumed 1 byte was one charac‐
177       ter and occupied one column position  when  written  out.  This  is  no
178       longer  always true. Since the most common usage of fold is believed to
179       be folding long lines for output to limited-length output devices, this
180       capability  was  preserved as the default case. The -b option was added
181       so that applications could fold files with arbitrary length lines  into
182       text files that could then be processed by the standard utilities. Note
183       that although the width for the -b option is in bytes, a line is  never
184       split in the middle of a character.  (It is unspecified what happens if
185       a width is specified that is too small to hold a single character found
186       in the input followed by a <newline>.)
187
188       The  tab stops are hardcoded to be every eighth column to meet histori‐
189       cal practice. No new method of specifying other tab stops was invented.
190

FUTURE DIRECTIONS

192       None.
193

SEE ALSO

195       cut
196
197       The Base Definitions volume of  POSIX.1‐2017,  Chapter  8,  Environment
198       Variables, Section 12.2, Utility Syntax Guidelines
199
201       Portions  of  this text are reprinted and reproduced in electronic form
202       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
203       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
204       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
205       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
206       event of any discrepancy between this version and the original IEEE and
207       The  Open Group Standard, the original IEEE and The Open Group Standard
208       is the referee document. The original Standard can be  obtained  online
209       at http://www.opengroup.org/unix/online.html .
210
211       Any  typographical  or  formatting  errors that appear in this page are
212       most likely to have been introduced during the conversion of the source
213       files  to  man page format. To report such errors, see https://www.ker
214       nel.org/doc/man-pages/reporting_bugs.html .
215
216
217
218IEEE/The Open Group                  2017                             FOLD(1P)
Impressum