当拒绝访问/tmp/时,在哪里创建临时文件? [英] Where to create temp files when access to /tmp/ is denied?

查看:46
本文介绍了当拒绝访问/tmp/时,在哪里创建临时文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简短的bash脚本来完成一项任务,其中涉及创建一个临时目录并在其中存储各种文件,并对它执行各种操作.

I wrote a short bash script to complete a task that involves creating a temporary directory and storing various files in it and performing various operations on it.

在我的第一遍中,我只是在/tmp/$$.$script中创建了临时目录",但是随后我在没有对/tmp/的写访问权的计算机上测试了该脚本.我想问的是这个temp目录的好辅助位置在哪里?我应该只使用当前目录吗?主目录?〜/tmp/?脚本的输出位置?

In my first pass I just created the temp dir at /tmp/$$.$script", but then I tested the script on a computer where I didn't have write access to /tmp/, and I'd like to take that case into account. So my question is where's a good secondary location for this temp dir? Should I just use the current directory? The home directory? ~/tmp/? The output location of the script?

所有创建的文件都会在脚本退出时清除.

All created files do get cleaned up on script exit.

推荐答案

许多系统还具有/var/tmp .如果系统管理员不希望您写入/tmp ,则可能是他们提供了一些替代方法……是否设置了 $ TMPDIR 环境变量?例如,在我的Mac上:

Many systems also have a /var/tmp. If the sysadmin doesn't want you writing in to /tmp, presumably they have provided some alternative… is the $TMPDIR environment variable set? For example, on my Mac:

$ echo $TMPDIR
/var/folders/jf/jfu4pjGtGGGkUuuq8HL7UE+++TI/-Tmp-/

这篇关于当拒绝访问/tmp/时,在哪里创建临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆