xref: /openbsd-src/bin/cat/cat.1 (revision ca1e11fc670dd7ab2902db6a936277c78a36611c)
1.\"	$OpenBSD: cat.1,v 1.37 2024/08/01 14:08:07 jmc Exp $
2.\"	$NetBSD: cat.1,v 1.12 1995/09/27 05:38:55 cgd Exp $
3.\"
4.\" Copyright (c) 1989, 1990, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Institute of Electrical and Electronics Engineers, Inc.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)cat.1	8.3 (Berkeley) 5/2/95
35.\"
36.Dd $Mdocdate: August 1 2024 $
37.Dt CAT 1
38.Os
39.Sh NAME
40.Nm cat
41.Nd concatenate and print files
42.Sh SYNOPSIS
43.Nm cat
44.Op Fl benstuv
45.Op Ar
46.Sh DESCRIPTION
47The
48.Nm
49utility reads files sequentially, writing them to the standard output.
50The
51.Ar file
52operands are processed in command-line order.
53If
54.Ar file
55is a single dash
56.Pq Sq -
57or absent,
58.Nm
59reads from the standard input.
60.Pp
61The options are as follows:
62.Bl -tag -width Ds
63.It Fl b
64Number the lines, but don't count blank lines.
65.It Fl e
66Print a dollar sign
67.Pq Ql \&$
68at the end of each line.
69Implies the
70.Fl v
71option to display non-printing characters.
72.It Fl n
73Number the output lines, starting at 1.
74.It Fl s
75Squeeze multiple adjacent empty lines, causing the output to be
76single spaced.
77.It Fl t
78Print tab characters as
79.Ql ^I .
80Implies the
81.Fl v
82option to display non-printing characters.
83.It Fl u
84The output is guaranteed to be unbuffered (see
85.Xr setvbuf 3 ) .
86.It Fl v
87Displays non-printing characters so they are visible.
88Control characters print as
89.Ql ^X
90for control-X, with the exception of the tab and EOL characters,
91which are displayed normally.
92The DEL character (octal 0177) prints as
93.Ql ^? .
94Non-ASCII characters (with the high bit set) are printed as
95.Ql M-
96(for meta) followed by the character for the low 7 bits.
97.El
98.Sh EXIT STATUS
99.Ex -std cat
100.Sh EXAMPLES
101Print the contents of
102.Ar file1
103to the standard output:
104.Pp
105.Dl $ cat file1
106.Pp
107Sequentially print the contents of
108.Ar file1
109and
110.Ar file2
111to the file
112.Ar file3 ,
113truncating
114.Ar file3
115if it already exists.
116See the manual page for your shell (e.g.,
117.Xr sh 1 )
118for more information on redirection.
119.Pp
120.Dl $ cat file1 file2 > file3
121.Pp
122Print the contents of
123.Ar file1 ,
124print data it receives from the standard input until it receives an
125.Dv EOF
126.Pq Sq ^D
127character, print the contents of
128.Ar file2 ,
129read and output contents of the standard input again, then finally output
130the contents of
131.Ar file3 .
132Note that if the standard input referred to a file, the second dash
133on the command line would have no effect, since the entire contents of the file
134would have already been read and printed by
135.Nm
136when it encountered the first
137.Ql \&-
138operand.
139.Pp
140.Dl $ cat file1 - file2 - file3
141.Sh SEE ALSO
142.Xr head 1 ,
143.Xr less 1 ,
144.Xr more 1 ,
145.Xr pr 1 ,
146.Xr sh 1 ,
147.Xr tail 1 ,
148.Xr vis 1 ,
149.Xr setvbuf 3
150.Rs
151.%A Rob Pike
152.%T "UNIX Style, or cat -v Considered Harmful"
153.%J "USENIX Summer Conference Proceedings"
154.%D 1983
155.Re
156.Sh STANDARDS
157The
158.Nm
159utility is compliant with the
160.St -p1003.1-2024
161specification.
162.Pp
163The flags
164.Op Fl benstv
165are extensions to that specification.
166.Sh HISTORY
167A
168.Nm
169utility appeared in
170.At v1 .
171.Sh CAVEATS
172Because of the shell language mechanism used to perform output
173redirection, the following command will cause the original data in
174.Ar file1
175to be destroyed:
176.Pp
177.Dl $ cat file1 file2 > file1
178.Pp
179To append
180.Ar file2
181to
182.Ar file1 ,
183instead use:
184.Pp
185.Dl $ cat file2 >> file1
186