-
Notifications
You must be signed in to change notification settings - Fork 9
/
tempfile.1
92 lines (91 loc) · 2.12 KB
/
tempfile.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
.\" -*- nroff -*-
.TH TEMPFILE 1 "30 May 2011" "Debian"
.SH NAME
tempfile \- create a temporary file in a safe manner
.SH SYNOPSIS
.B tempfile
[\-d DIR] [\-p STRING] [\-s STRING] [\-m MODE] [\-n FILE] [\-\-directory=DIR]
[\-\-prefix=STRING] [\-\-suffix=STRING] [\-\-mode=MODE] [\-\-name=FILE] [\-\-help] [\-\-version]
.SH DESCRIPTION
.PP
.B tempfile
creates a temporary file in a safe manner. It uses
.BR tempnam (3)
to choose the name and opens it with O_RDWR | O_CREAT | O_EXCL. The filename
is printed on standard output. See
.BR tempnam (3)
for the actual steps involved in directory selection.
.PP
The directory in which to create the file might be searched for in this
order (but refer to
.BR tempnam (3)
for authoritative answers):
.TP 3
a)
In case the environment variable
.B TMPDIR
exists and
contains the name of an appropriate directory, that is used.
.TP
b)
Otherwise, if the
.I \-\-directory
argument is specified and appropriate, it is used.
.TP
c)
Otherwise,
.I P_tmpdir
(as defined in
.IR <stdio.h> )
is used when appropriate.
.TP
d)
Finally an implementation-defined directory
.IR (/tmp)
may be used.
.SH OPTIONS
.TP
.BI "-d, --directory " DIR
Place the file in DIR.
.TP
.BI "-m, --mode " MODE
Open the file with MODE instead of 0600.
.TP
.BI "-n, --name " FILE
Use FILE for the name instead of
.BR tempnam (3) .
The options -d, -p, and -s are ignored if this option is given.
.TP
.BI "-p, --prefix " STRING
Use up to five letters of STRING to generate the name.
.TP
.BI "-s, --suffix " STRING
Generate the file with STRING as the suffix.
.TP
.B "--help"
Print a usage message on standard output and exit successfully.
.TP
.B "--version"
Print version information on standard output and exit successfully.
.SH RETURN VALUES
An exit status of 0 means the temporary file was created successfully.
Any other exit status indicates an error.
.SH BUGS
Exclusive creation is not guaranteed when creating files on NFS
partitions. tempfile is deprecated; you should use mktemp(1)
instead.
.SH EXAMPLE
.RS
.nf
#!/bin/sh
#[...]
t=$(tempfile) || exit
trap "rm -f -- '$t'" EXIT
#[...]
rm -f -- "$t"
trap - EXIT
exit
.fi
.SH "SEE ALSO"
.BR tempnam (3),
.BR mktemp (1)