xref: /netbsd-src/bin/cat/cat.1 (revision cb8c8a822afb5f66a08d99fa19412d0ffafa42f2)
1.\"	$NetBSD: cat.1,v 1.41 2017/10/02 08:24:17 wiz Exp $
2.\"
3.\" Copyright (c) 1989, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" the Institute of Electrical and Electronics Engineers, Inc.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.\"     @(#)cat.1	8.3 (Berkeley) 5/2/95
34.\"
35.Dd June 15, 2014
36.Dt CAT 1
37.Os
38.Sh NAME
39.Nm cat
40.Nd concatenate and print files
41.Sh SYNOPSIS
42.Nm
43.Op Fl beflnstuv
44.Op Fl B Ar bsize
45.Op Fl
46.Op Ar
47.Sh DESCRIPTION
48The
49.Nm
50utility reads files sequentially, writing them to the standard output.
51The
52.Ar file
53operands are processed in command line order.
54A single dash represents the standard input,
55and may appear multiple times in the
56.Ar file
57list.
58If no
59.Ar file
60operands are given, standard input is read.
61.Pp
62The word
63.Dq concatenate
64is just a verbose synonym for
65.Dq catenate .
66.Pp
67The options are as follows:
68.Bl -tag -width Ds
69.It Fl B Ar bsize
70Read with a buffer size of
71.Ar bsize
72bytes, instead of the default buffer size which is the blocksize of the
73output file.
74.It Fl b
75Implies the
76.Fl n
77option, but doesn't number blank lines.
78.It Fl e
79Implies the
80.Fl v
81option, and displays a dollar sign
82.Pq Ql \&$
83at the end of each line
84as well.
85.It Fl f
86Only attempt to display regular files.
87.It Fl l
88Set an exclusive advisory lock on the standard output file descriptor.
89This lock is set using
90.Xr fcntl 2
91with the
92.Dv F_SETLKW
93command.
94If the output file is already locked,
95.Nm
96will block until the lock is acquired.
97.It Fl n
98Number the output lines, starting at 1.
99.It Fl s
100Squeeze multiple adjacent empty lines, causing the output to be
101single spaced.
102.It Fl t
103Implies the
104.Fl v
105option, and displays tab characters as
106.Ql ^I
107as well.
108.It Fl u
109The
110.Fl u
111option guarantees that the output is unbuffered.
112.It Fl v
113Displays non-printing characters so they are visible.
114Control characters print as
115.Ql ^X
116for control-X; the delete
117character (octal 0177) prints as
118.Ql ^? .
119Non-ascii characters (with the high bit set) are printed as
120.Ql M-
121(for meta) followed by the character for the low 7 bits.
122.El
123.Sh EXIT STATUS
124.Ex -std cat
125.Sh EXAMPLES
126The command:
127.Bd -literal -offset indent
128.Ic cat file1
129.Ed
130.Pp
131will print the contents of
132.Ar file1
133to the standard output.
134.Pp
135The command:
136.Bd -literal -offset indent
137.Ic cat file1 file2 > file3
138.Ed
139.Pp
140will sequentially print the contents of
141.Ar file1
142and
143.Ar file2
144to the file
145.Ar file3 ,
146truncating
147.Ar file3
148if it already exists.
149See the manual page for your shell (e.g.,
150.Xr sh 1 )
151for more information on redirection.
152.Pp
153The command:
154.Bd -literal -offset indent
155.Ic cat file1 - file2 - file3
156.Ed
157.Pp
158will print the contents of
159.Ar file1 ,
160print data it receives from the standard input until it receives an
161.Dv EOF
162.Pq Sq ^D
163character, print the contents of
164.Ar file2 ,
165read and output contents of the standard input again, then finally output
166the contents of
167.Ar file3 .
168Note that if the standard input referred to a file, the second dash
169on the command-line would have no effect, since the entire contents of the file
170would have already been read and printed by
171.Nm
172when it encountered the first
173.Ql \&-
174operand.
175.Sh SEE ALSO
176.Xr head 1 ,
177.Xr hexdump 1 ,
178.Xr lpr 1 ,
179.Xr more 1 ,
180.Xr pr 1 ,
181.Xr tac 1 ,
182.Xr tail 1 ,
183.Xr view 1 ,
184.Xr vis 1 ,
185.Xr fcntl 2
186.Rs
187.%A Rob Pike
188.%T "UNIX Style, or cat -v Considered Harmful"
189.%J "USENIX Summer Conference Proceedings"
190.%D 1983
191.Re
192.Sh STANDARDS
193The
194.Nm
195utility is expected to conform to the
196.St -p1003.2-92
197specification.
198.Pp
199The flags
200.Op Fl Bbeflnstv
201are extensions to the specification.
202.Sh HISTORY
203A
204.Nm
205utility appeared in
206.At v1 .
207Dennis Ritchie designed and wrote the first man page.
208It appears to have been
209.Xr cat 1 .
210.Sh BUGS
211Because of the shell language mechanism used to perform output
212redirection, the command
213.Dq Li cat file1 file2 > file1
214will cause the original data in file1 to be destroyed!
215This is performed by the shell before
216.Nm
217is run.
218