tempfile和mktemp有什么区别? [英] What's the difference between tempfile and mktemp?
问题描述
我遇到的大多数系统都具有tempfile(1)
和mktemp(1)
.有句法上的区别,mktemp
也可以创建目录,但是否则它们似乎做相同的事情.
Most systems I've encountered have both tempfile(1)
and mktemp(1)
. There are syntactic differences, and mktemp
can also create directories, but they otherwise seem to do the same thing.
两者之间有区别吗?为什么两者都存在?一个比另一个更标准吗?如果我只想安全地创建一个临时文件,是否有理由比另一个优先?
Is there any difference between the two? Why do both exist? Is one more standard than the other? If I just want to create a temporary file safely, is there any reason to prefer one over the other?
我怀疑这背后有一些有趣的Unix知识,但是我的搜索没有任何结果.
I suspect there's some interesting Unix lore behind this, but my searches turn up nothing.
推荐答案
我怀疑这背后有一些有趣的Unix知识...
I suspect there's some interesting Unix lore behind this ...
mktemp
的历史记录可以追溯到此帖子宣布为coreutils
包含mktemp
.
The history of mktemp
can be traced to OpenBSD 2.1. However, it became a part of GNU coreutils much later. This post announced the inclusion of mktemp
for coreutils
.
直到那时,许多程序都在使用tempfile
.还有一个提案可以使tempfile
围绕mktemp
,已被拒绝以阻止使用tempfile
.
Until then, tempfile
was being used by a number of programs. There was also a proposal to make tempfile
a wrapper around mktemp
, which was rejected to discourage use of tempfile
.
但是,以下内容已添加到tempfile
手册中:
However, the following was added to tempfile
manual:
在NFS分区上创建文件时,不能保证专有创建.
tempfile
无法建立临时目录.tempfile
已过时;您应该改用mktemp(1)
.
Exclusive creation is not guaranteed when creating files on NFS partitions.
tempfile
cannot make temporary directories.tempfile
is deprecated; you should usemktemp(1)
instead.
这篇关于tempfile和mktemp有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!