zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Shell脚本攻略学习笔记十二之mktemp命令

笔记学习命令shell 脚本 攻略 十二
2023-09-14 09:13:15 时间

Shell脚本攻略学习笔记十二之mktemp命令

mktemp — create a temporary file or directory

  • Create a temporary file as follows
[root@server4 shells]# mktemp
/tmp/tmp.MeH1jVsPRi
  • To create a temporary directory, use the following commands
[root@server4 shells]# mktemp -d
/tmp/tmp.AThosQe1lF
[root@server4 shells]# cd /tmp/tmp.AThosQe1lF/
[root@server4 tmp.AThosQe1lF]# ll
total 0
  • To just generate a filename without actually creating a file or directory, use this:
[root@server4 shells]# mktemp -u
/tmp/tmp.3z6y2RQlUp
[root@server4 shells]# cd /tmp/tmp.3z6y2RQlUp
-bash: cd: /tmp/tmp.3z6y2RQlUp: No such file or directory   #提示不存在
  • To create the temporary filename according to a template, use:
[root@server4 shells]# mktemp test.XXX
test.okb
[root@server4 shells]# mktemp test.xxx
mktemp: too few X's in template ‘test.xxx’
[root@server4 shells]# mktemp test.XX
mktemp: too few X's in template ‘test.XX’
[root@server4 shells]# mktemp test.XXX
test.xv6
[root@server4 shells]# mktemp HH.XXX
HH.8Yy
[root@server4 shells]# mktemp LIUBAI.XXX
LIUBAI.vZ9