usched: Allow process to change self cpu affinity
[dragonfly.git] / usr.bin / mktemp / mktemp.1
blobb1eac7a62071845646b1498f96f71eae85694c20
1 .\" Copyright (c) 1989, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\" From: $OpenBSD: mktemp.1,v 1.8 1998/03/19 06:13:37 millert Exp $
29 .\" $FreeBSD: src/usr.bin/mktemp/mktemp.1,v 1.7.2.8 2003/02/24 22:37:42 trhodes Exp $
30 .\" $DragonFly: src/usr.bin/mktemp/mktemp.1,v 1.4 2006/02/17 19:39:09 swildner Exp $
31 .\"
32 .Dd November 3, 2012
33 .Dt MKTEMP 1
34 .Os
35 .Sh NAME
36 .Nm mktemp
37 .Nd make temporary file name (unique)
38 .Sh SYNOPSIS
39 .Nm
40 .Op Fl d
41 .Op Fl q
42 .Op Fl t Ar prefix
43 .Op Fl u
44 .Ar template ...
45 .Nm
46 .Op Fl d
47 .Op Fl q
48 .Op Fl u
49 .Fl t Ar prefix
50 .Sh DESCRIPTION
51 The
52 .Nm
53 utility takes each of the given file name templates and overwrites a
54 portion of it to create a file name.
55 This file name is unique
56 and suitable for use by the application.
57 The template may be
58 any file name with some number of
59 .Ql X Ns s
60 appended
61 to it, for example
62 .Pa /tmp/temp.XXXX .
63 The trailing
64 .Ql X Ns s
65 are replaced with the current process number and/or a
66 unique letter combination.
67 The number of unique file names
68 .Nm
69 can return depends on the number of
70 .Ql X Ns s
71 provided; six
72 .Ql X Ns s
73 will
74 result in
75 .Nm
76 selecting 1 of 56800235584 (62 ** 6) possible file names.
77 .Pp
79 .Nm
80 can successfully generate a unique file name, the file
81 is created with mode 0600 (unless the
82 .Fl u
83 flag is given) and the filename is printed
84 to standard output.
85 .Pp
86 If the
87 .Fl t Ar prefix
88 option is given,
89 .Nm
90 will generate a template string based on the
91 .Ar prefix
92 and the
93 .Ev TMPDIR
94 environment variable if set.
95 The default location if
96 .Ev TMPDIR
97 is not set is
98 .Pa /tmp .
99 Care should
100 be taken to ensure that it is appropriate to use an environment variable
101 potentially supplied by the user.
103 If no arguments are passed or if only the
104 .Fl d
105 flag is passed
107 behaves as if
108 .Fl t Li tmp
109 was supplied.
111 Any number of temporary files may be created in a single invocation,
112 including one based on the internal template resulting from the
113 .Fl t
114 flag.
118 utility is provided to allow shell scripts to safely use temporary files.
119 Traditionally, many shell scripts take the name of the program with
120 the pid as a suffix and use that as a temporary file name.
121 This
122 kind of naming scheme is predictable and the race condition it creates
123 is easy for an attacker to win.
124 A safer, though still inferior, approach
125 is to make a temporary directory using the same naming scheme.
126 While
127 this does allow one to guarantee that a temporary file will not be
128 subverted, it still allows a simple denial of service attack.
129 For these
130 reasons it is suggested that
132 be used instead.
133 .Sh OPTIONS
134 The available options are as follows:
135 .Bl -tag -width indent
136 .It Fl d
137 Make a directory instead of a file.
138 .It Fl q
139 Fail silently if an error occurs.
140 This is useful if
141 a script does not want error output to go to standard error.
142 .It Fl t Ar prefix
143 Generate a template (using the supplied
144 .Ar prefix
146 .Ev TMPDIR
147 if set) to create a filename template.
148 .It Fl u
149 Operate in
150 .Dq unsafe
151 mode.
152 The temp file will be unlinked before
154 exits.
155 This is slightly better than
156 .Xr mktemp 3
157 but still introduces a race condition.
158 Use of this
159 option is not encouraged.
161 .Sh EXIT STATUS
162 .Ex -std
163 .Sh EXAMPLES
164 The following
165 .Xr sh 1
166 fragment illustrates a simple use of
168 where the script should quit if it cannot get a safe
169 temporary file.
170 .Bd -literal -offset indent
171 tempfoo=`basename $0`
172 TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1
173 echo "program output" >> $TMPFILE
176 To allow the use of $TMPDIR:
177 .Bd -literal -offset indent
178 tempfoo=`basename $0`
179 TMPFILE=`mktemp -t ${tempfoo}` || exit 1
180 echo "program output" >> $TMPFILE
183 In this case, we want the script to catch the error itself.
184 .Bd -literal -offset indent
185 tempfoo=`basename $0`
186 TMPFILE=`mktemp -q /tmp/${tempfoo}.XXXXXX`
187 if [ $? -ne 0 ]; then
188         echo "$0: Can't create temp file, exiting..."
189         exit 1
192 .Sh SEE ALSO
193 .Xr mkdtemp 3 ,
194 .Xr mkstemp 3 ,
195 .Xr mktemp 3 ,
196 .Xr environ 7
197 .Sh HISTORY
200 utility appeared in
201 .Ox 2.1 .
202 This implementation was written independently based on the
204 man page, and
205 first appeared in
206 .Fx 2.2.7 .
207 This man page is taken from
208 .Ox .