TEMPFILE(1)
โจ NAME โจ
Okay bestie, meet tempfile from the TEMPFILE(1) manual page ๐ง. Its whole job is to make a temporary file in a safe way ๐
๐ SYNOPSIS ๐
tempfile [-d DIR] [-p STRING] [-s STRING] [-m MODE] [-n FILE]
[--directory=DIR] [--prefix=STRING] [--suffix=STRING] [--mode=MODE]
[--name=FILE] [--help] [--version]
๐ DESCRIPTION ๐
okay so tempfile creates a temporary file the safe way ๐
It uses mkstemps(3) to pick the name, then opens it with O_RDWR | O_CREAT | O_EXCL. Once it's made, the filename gets printed on standard output ๐ฆ
The directory where the file gets created is picked in this order, no cap:
a) If the environment variable TMPDIR exists and holds the name of a valid directory, that wins ๐
b) Otherwise, if the --directory argument is given and it's valid, that gets used ๐ธ
c) Otherwise, P_tmpdir (as defined in <stdio.h>) gets used when it makes sense ๐ซถ
d) Finally, an implementation-defined directory (/tmp) might get used โจ
๐ OPTIONS ๐
-d,--directory DIRโ put the file insideDIR๐-m,--mode MODEโ open the file withMODEinstead of the default0600๐-n,--name FILEโ useFILEas the name instead of going throughtempnam(3). Heads up:-d,-p, and-sget ignored if you pass this one ๐-p,--prefix STRINGโ grab up to five letters ofSTRINGto build the name ๐ง-s,--suffix STRINGโ make the file withSTRINGtacked on as the suffix ๐--helpโ prints a usage message on standard output and exits successfully ๐--versionโ prints version info on standard output and exits successfully ๐ฅ
๐ง RETURN VALUES ๐ง
An exit status of 0 means the temp file got created successfully โจ Literally any other exit status means something went wrong ๐
๐ BUGS ๐
โ ๏ธ Exclusive creation is not guaranteed when you're making files on NFS partitions. Be careful bestie!
tempfile can't make temporary directories, so don't even try ๐ญ Also, tempfile is deprecated, so you should use mktemp(1) instead ๐
๐ EXAMPLE ๐
Here's how you'd use it in a shell script, periodt:
#!/bin/sh
#[...]
t=$(tempfile) || exit
trap "rm -f -- '$t'" EXIT
#[...]
rm -f -- "$t"
trap - EXIT
exit
๐ฆ SEE ALSO ๐ฆ
tempnam(3), mktemp(1) ๐ซถ
Bye bestie, that's the whole TEMPFILE(1) tea ๐ Debian, 27 Jun 2012 vibes forever ๐โจ
๐ฆ where this page comes from
- debian bookworm: debianutils 5.7-0.5~deb12u1 ยท GPL-2.0-or-later
- debian trixie: debianutils 5.23.2 ยท GPL-2.0-or-later
- nixpkgs unstable: debianutils 5.23.2
- ubuntu jammy: debianutils 5.5-1ubuntu2
- ubuntu noble: debianutils 5.17build1 ยท GPL-2.0-or-later
- ubuntu questing: debianutils 5.23.2 ยท GPL-2.0-or-later
- ubuntu resolute: debianutils 5.23.2build1 ยท GPL-2.0-or-later
- ubuntu stonking: debianutils 5.24 ยท GPL-2.0-or-later
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms