Main index | Section 1 | 日本語 | Options |
If
mktemp
can successfully generate a unique file name, the file
is created with mode 0600 (unless the
If the
If no arguments are passed or if only the
Any number of temporary files may be created in a single invocation,
including one based on the internal template resulting from the
The mktemp utility is provided to allow shell scripts to safely use temporary files. Traditionally, many shell scripts take the name of the program with the pid as a suffix and use that as a temporary file name. This kind of naming scheme is predictable and the race condition it creates is easy for an attacker to win. A safer, though still inferior, approach is to make a temporary directory using the same naming scheme. While this does allow one to guarantee that a temporary file will not be subverted, it still allows a simple denial of service attack. For these reasons it is suggested that mktemp be used instead.
| |
Make a directory instead of a file. | |
| |
Fail silently if an error occurs. This is useful if a script does not want error output to go to standard error. | |
| |
Generate a template (using the supplied prefix and TMPDIR if set) to create a filename template. | |
| |
Operate in "unsafe" mode. The temp file will be unlinked before mktemp exits. This is slightly better than mktemp(3) but still introduces a race condition. Use of this option is not encouraged. | |
tempfoo=`basename $0` TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || exit 1 echo "program output" >> $TMPFILE
To allow the use of $TMPDIR:
tempfoo=`basename $0` TMPFILE=`mktemp -t ${tempfoo}` || exit 1 echo "program output" >> $TMPFILE
In this case, we want the script to catch the error itself.
tempfoo=`basename $0` TMPFILE=`mktemp -q /tmp/${tempfoo}.XXXXXX` if [ $? -ne 0 ]; then echo "$0: Can't create temp file, exiting..." exit 1 fi
MKTEMP (1) | December 30, 2005 |
Main index | Section 1 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | UNIX has been evolving feverishly for close to 30 years, sort of like bacteria in a cesspool — only not as attractive | ” |
— John Levine, "Unix for Dummies" |