1CAT(1P) POSIX Programmer's Manual CAT(1P)
2
3
4
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
12 cat — concatenate and print files
13
15 cat [-u] [file...]
16
18 The cat utility shall read files in sequence and shall write their con‐
19 tents to the standard output in the same sequence.
20
22 The cat utility shall conform to the Base Definitions volume of
23 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
24
25 The following option shall be supported:
26
27 -u Write bytes from the input file to the standard output with‐
28 out delay as each is read.
29
31 The following operand shall be supported:
32
33 file A pathname of an input file. If no file operands are speci‐
34 fied, the standard input shall be used. If a file is '-', the
35 cat utility shall read from the standard input at that point
36 in the sequence. The cat utility shall not close and reopen
37 standard input when it is referenced in this way, but shall
38 accept multiple occurrences of '-' as a file operand.
39
41 The standard input shall be used only if no file operands are speci‐
42 fied, or if a file operand is '-'. See the INPUT FILES section.
43
45 The input files can be any file type.
46
48 The following environment variables shall affect the execution of cat:
49
50 LANG Provide a default value for the internationalization vari‐
51 ables that are unset or null. (See the Base Definitions vol‐
52 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
53 ables for the precedence of internationalization variables
54 used to determine the values of locale categories.)
55
56 LC_ALL If set to a non-empty string value, override the values of
57 all the other internationalization variables.
58
59 LC_CTYPE Determine the locale for the interpretation of sequences of
60 bytes of text data as characters (for example, single-byte as
61 opposed to multi-byte characters in arguments).
62
63 LC_MESSAGES
64 Determine the locale that should be used to affect the format
65 and contents of diagnostic messages written to standard
66 error.
67
68 NLSPATH Determine the location of message catalogs for the processing
69 of LC_MESSAGES.
70
72 Default.
73
75 The standard output shall contain the sequence of bytes read from the
76 input files. Nothing else shall be written to the standard output. If
77 the standard output is a regular file, and is the same file as any of
78 the input file operands, the implementation may treat this as an error.
79
81 The standard error shall be used only for diagnostic messages.
82
84 None.
85
87 None.
88
90 The following exit values shall be returned:
91
92 0 All input files were output successfully.
93
94 >0 An error occurred.
95
97 Default.
98
99 The following sections are informative.
100
102 The -u option has value in prototyping non-blocking reads from FIFOs.
103 The intent is to support the following sequence:
104
105
106 mkfifo foo
107 cat -u foo > /dev/tty13 &
108 cat -u > foo
109
110 It is unspecified whether standard output is or is not buffered in the
111 default case. This is sometimes of interest when standard output is
112 associated with a terminal, since buffering may delay the output. The
113 presence of the -u option guarantees that unbuffered I/O is available.
114 It is implementation-defined whether the cat utility buffers output if
115 the -u option is not specified. Traditionally, the -u option is imple‐
116 mented using the equivalent of the setvbuf() function defined in the
117 System Interfaces volume of POSIX.1‐2017.
118
120 The following command:
121
122
123 cat myfile
124
125 writes the contents of the file myfile to standard output.
126
127 The following command:
128
129
130 cat doc1 doc2 > doc.all
131
132 concatenates the files doc1 and doc2 and writes the result to doc.all.
133
134 Because of the shell language mechanism used to perform output redi‐
135 rection, a command such as this:
136
137
138 cat doc doc.end > doc
139
140 causes the original data in doc to be lost before cat even begins exe‐
141 cution. This is true whether the cat command fails with an error or
142 silently succeeds (the specification allows both behaviors). In order
143 to append the contents of doc.end without losing the original contents
144 of doc, this command should be used instead:
145
146
147 cat doc.end >> doc
148
149 The command:
150
151
152 cat start - middle - end > file
153
154 when standard input is a terminal, gets two arbitrary pieces of input
155 from the terminal with a single invocation of cat. Note, however, that
156 if standard input is a regular file, this would be equivalent to the
157 command:
158
159
160 cat start - middle /dev/null end > file
161
162 because the entire contents of the file would be consumed by cat the
163 first time '-' was used as a file operand and an end-of-file condition
164 would be detected immediately when '-' was referenced the second time.
165
167 Historical versions of the cat utility include the -e, -t, and -v,
168 options which permit the ends of lines, <tab> characters, and invisible
169 characters, respectively, to be rendered visible in the output. The
170 standard developers omitted these options because they provide too fine
171 a degree of control over what is made visible, and similar output can
172 be obtained using a command such as:
173
174
175 sed -n l pathname
176
177 The latter also has the advantage that its output is unambiguous,
178 whereas the output of historical cat -etv is not.
179
180 The -s option was omitted because it corresponds to different functions
181 in BSD and System V-based systems. The BSD -s option to squeeze blank
182 lines can be accomplished by the shell script shown in the following
183 example:
184
185
186 sed -n '
187 # Write non-empty lines.
188 /./ {
189 p
190 d
191 }
192 # Write a single empty line, then look for more empty lines.
193 /^$/ p
194 # Get next line, discard the held <newline> (empty line),
195 # and look for more empty lines.
196 :Empty
197 /^$/ {
198 N
199 s/.//
200 b Empty
201 }
202 # Write the non-empty line before going back to search
203 # for the first in a set of empty lines.
204 p
205 '
206
207 The System V -s option to silence error messages can be accomplished by
208 redirecting the standard error. Note that the BSD documentation for cat
209 uses the term ``blank line'' to mean the same as the POSIX ``empty
210 line'': a line consisting only of a <newline>.
211
212 The BSD -n option was omitted because similar functionality can be
213 obtained from the -n option of the pr utility.
214
216 None.
217
219 more
220
221 The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment
222 Variables, Section 12.2, Utility Syntax Guidelines
223
224 The System Interfaces volume of POSIX.1‐2017, setvbuf()
225
227 Portions of this text are reprinted and reproduced in electronic form
228 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
229 table Operating System Interface (POSIX), The Open Group Base Specifi‐
230 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
231 Electrical and Electronics Engineers, Inc and The Open Group. In the
232 event of any discrepancy between this version and the original IEEE and
233 The Open Group Standard, the original IEEE and The Open Group Standard
234 is the referee document. The original Standard can be obtained online
235 at http://www.opengroup.org/unix/online.html .
236
237 Any typographical or formatting errors that appear in this page are
238 most likely to have been introduced during the conversion of the source
239 files to man page format. To report such errors, see https://www.ker‐
240 nel.org/doc/man-pages/reporting_bugs.html .
241
242
243
244IEEE/The Open Group 2017 CAT(1P)