Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux basic command-mktemp

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Mktemp

It is safe to create temporary files or directories. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Mktemp [options] [TEMPLATE]

2. List of options

Option

Description

-- version

Display command version information

-- help

Display help information

-d |-- directory

Create a directory

-u |-- dry-run

Don't create anything, just print a name (not safe)

-Q |-- quiet

No prompt message is displayed when an error occurs

-- suffix=SUFF

Attach SUFF to the template. SUFF cannot contain slashes. Use this option if the template does not end with X.

-- tmpdir [= dir]

Specify the path to the temporary file, and if there is no path after tmpdir, use the variable $TMPDIR;. If this variable is not specified, the temporary file is created in the / tmp directory. With this option, the template cannot be an absolute name. Unlike "- t", templates may contain slashes, but mktemp only creates the final component

-p DIR

Use DIR as prefix

-t

Interpret the template as a single filename component relative to the directory $TMPDIR (if set); otherwise, the directory specified by-p; or use / tmp (- t has been deprecated)

TEMPLATE

Temporary file name, which must contain at least 3 Xs. If not specified, the default is tmp. XXXXXXXXXX

3. Examples

1) create a temporary file

[root@localhost weijie] # mktemp wj123.XXXX / / the name contains 4 Xs

Wj123.kpET

You have new mail in / var/spool/mail/root

[root@localhost weijie] # mktemp wj123.XXXXXX / / the name contains 6 Xs

Wj123.oH2o4P

[root@localhost weijie] # ls

1.c wj123.kpET wj123.oH2o4P

2) create a temporary directory

[root@localhost weijie] # mktemp-d wjtp / / No X in the name

Mktemp: too little X in template "wjtp"

[root@localhost weijie] # mktemp-d wjtpxxx / / there is no X in the name. You can see here that X must be uppercase.

Mktemp: too little X in template "wjtpxxx"

[root@localhost weijie] # mktemp-d wjtpXXX / / created successfully

WjtpflR

[root@localhost weijie] # ls-l

Total dosage 4

-rw-r--r-- 1 root root 7 September 09:11 1.c

-rw- 1 root root 7 September 14:47 wj123.kpET

-rw- 1 root root 7 September 14:47 wj123.oH2o4P

Drwx- 2 root root 4096 September 7 14:50 wjtpflR

3) create a temporary file in / tmp

[root@localhost weijie] # mktemp-- tmpdir wj234.XXX / / tmpdir does not specify a path and is created under tmp

/ tmp/wj234.BNy

You have new mail in / var/spool/mail/root

4) create a temporary directory under the specified directory

[root@localhost weijie] # mktemp-- tmpdir=/weijie wj234.XXX / / created under the path specified by tmpdir

/ weijie/wj234.q1C

[root@localhost weijie] # ls

1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR

5) use the option-u to create

[root@localhost weijie] # mktemp-u wj123.XXXXXX / / use the-u option

Wj123.dSgIKl

[root@localhost weijie] # ls / / cannot see the temporary file because it was not created

1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report