Manpages

名 前

tempfile - 安 全 な 一 時 フ ァ イ ル の 作 成

書 式

tempfile [-d DIR] [-p STRING] [-s STRING] [-m MODE] [-n FILE] [--directory=DIR] [--prefix=STRING] [--suffix=STRING] [--mode=MODE] [--name=FILE] [--help] [--version]

説 明

tempfile creates a temporary file in a safe manner. It uses mkstemps(3) to choose the name and opens it with O_RDWR | O_CREAT | O_EXCL. The filename is printed on standard output.

The directory in which to create the file might be searched for in this order:

a) 環 境 変 数

TMPDIR が 存 在 し 、 適 切 な デ ィ レ ク ト リ 名 が 設 定 さ れ て い れ ば 、 こ

れ を 使 用 し ま す 。

b) そ う で な い 場 合 、

--directory 引 数 が 指 定 さ れ て い て 適 切 で あ れ ば 、 こ れ を

使 用 し ま す 。

c) そ う で な い 場 合 、

P_tmpdir (<stdio.h> で 定 義 ) が 適 切 で あ れ ば 、 こ れ を 使

用 し ま す 。

d)

Finally an implementation-defined directory (/tmp) may be used.

オ プ シ ョ ン

-d, --directory DIR フ ァ イ ル を DIR に 配 置 し ま す 。
-m, --mode
MODE フ ァ イ ル の モ ー ド を 0600 に 代 え て MODE で 開 き ま す 。
-n, --name
FILE フ ァ イ ル 名 と し て tempnam(3) に 代 え て FILE を 使 用 し ま す 。 こ の オ プ シ ョ ン を 与 え る と 、 -d, -p, -s の 各 オ プ シ ョ ン を 無 視 し ま す 。
-p, --prefix
STRING

STRING の 5 文 字 ま で を 名 前 の 生 成 に 使 用 し ま す 。

-s, --suffix STRING

STRING を 末 尾 に す る フ ァ イ ル を 生 成 し ま す 。

--help 使 用 方 法 を 標 準 出 力 に 表 示 し 、 正 常 終 了 し ま す 。

--version バ ー ジ ョ ン 情 報 を 標 準 出 力 に 表 示 し 、 正 常 終 了 し ま す 。

戻 り 値

終 了 ス テ ー タ ス が 0 は 一 時 フ ァ イ ル が 正 常 に 作 成 で き た こ と を 意 味 し ま す 。 そ の 他 の 終 了 ス テ ー タ ス は エ ラ ー で す 。

バ グ

Exclusive creation is not guaranteed when creating files on NFS partitions. tempfile cannot make temporary directories. tempfile is deprecated; you should use mktemp(1) instead.

#!/bin/sh
#[...]
t=$(tempfile) || exit
trap "rm -f -- ’$t’" EXIT
#[...]
rm -f -- "$t"
trap - EXIT
exit

関 連 項 目

tempnam(3), mktemp(1)

翻 訳

倉 澤 望 <nabetaro [AT] debian.jp>, 2012

Debian JP Documentation ML <debian-doc [AT] debian.jp>