mktemp command

最适合存储临时数据的位置是/tmp, mktemp 命令可以为临时文件或目录创建唯一的名字

Create a temporary file or directory.

1
2
3
4
5
6
7
8
9
10
11
12
mktemp

Create a temporary file or directory.

- Create an empty temporary file and return the absolute path to it:
mktemp

- Create a temporary directory and return the absolute path to it:
mktemp -d

- Create a temporary file with a specified suffix:
mktemp --suffix ".txt"

1.create temporary file (创建临时目录)

1
2
3
$filename=`mktemp`
echo $filename
/tmp/tmp.8xefliegnD9

2. create temporary directory (创建临时目录)

1
2
3
dirname=`mktemp -d`
echo $dirname
tmp.NJ8dhf6wk
  • If you just want to generate a filename and don’t want to create the actual file or directory, you can(如果仅仅是想生成文件名,不希望创建实际的文件或目录,可以):
    mktemp -u

  • Create a temporary filename based on the tempplate(基于模板创建临时文件名)

    1
    2
    3
    4
    5
    6
    ➜  qr_blog mktemp study.XXX
    study.UWT
    ➜ qr_blog mktemp study.XXX
    study.Usm
    ➜ qr_blog mktemp study.XXX
    study.M6a

Mac OS 与linux用法略有区别,请视情况使用

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~