Detailed explanation of mktemp, a basic Linux command

Detailed explanation of mktemp, a basic Linux command

mktemp

Create temporary files or directories in a safe way. Applicable scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

mktemp [options] [TEMPLATE]

2. List of options

Options

illustrate

--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 (unsafe)

-q | --quiet

Do not display prompt information when an error occurs

--suffix=SUFF

Append SUFF to the template. SUFF cannot contain slashes. This option is used if the template does not end with X.

--tmpdir[=dir]

Specifies the path for temporary files. If there is no path after tmpdir, the variable $TMPDIR is used. 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 creates only 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 /tmp (-t is deprecated).

TEMPLATE

Temporary file name. The name must contain at least three letters X. 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 //There is no X in the name

mktemp: too few Xs in template "wjtp"

[root@localhost weijie]# mktemp -d wjtpxxx //There is no X in the name. Here you can see that X must be uppercase. mktemp: Too few Xs 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 0 Sep 7 09:11 1.c
-rw------ 1 root root 0 September 7 14:47 wj123.kpET
-rw------ 1 root root 0 Sep 7 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, create /tmp/wj234.BNy under tmp
You have new mail in /var/spool/mail/root

4) Create a temporary directory in the specified directory

[root@localhost weijie]# mktemp --tmpdir=/weijie wj234.XXX //Create /weijie/wj234.q1C in the path specified by tmpdir
[root@localhost weijie]# ls
1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR

5) Create using option -u

[root@localhost weijie]# mktemp -u wj123.XXXXXX //Use the -u option wj123.dSgIKl
[root@localhost weijie]#ls //Cannot see the temporary file because it is not created 1.c wj123.kpET wj123.oH2o4P wj234.q1C wjtpflR

Supplement: Linux basic commands

1. Basic commands

1. ls: List files or directories in the current directory

2. ls -a: List all files and directories in the current directory (including hidden files)

3. ls -l: Display detailed information of the file (long format information view), equivalent to ll

ls -hl: Display detailed information and file size of the file
ls -al: List detailed information of all files and directories in the current directory
ls -dl: Display detailed information about the current file itself

4. cat command: view file information (can only view files)

[root@com ~]# cat /etc/passwd: View all user information
[root@com ~]# cat /etc/group: View all user group information

Note: Every time a user is created in the Linux system, a corresponding user group will be automatically generated.

5. cd command: switch directory

 [root@com ~]# cd /etc: Switch to the etc directory under the root directory pwd: Display the directory of the current file whoami: View the current user [root@com etc]# whoami: View the current user is root user root

6. /: indicates the user's root directory

Home directory (host directory)

1) Home directory of the administrator user:

  [root@com ~]# pwd
    /root

2) Home directory of ordinary users:

[java17@com ~]$ pwd
    /home/java17

7. Switch user command: su - username

1) Switch to a normal user

  [root@com ~]# su - java17
  [java17@com ~]$ pwd
  /home/java17

2) Switch to the root administrator user

 [java17@com ~]$ su - or [java17@com ~]$ su - root
  Password:

8. Shutdown, restart, clear screen

Shutdown: halt, init 0, shutdown now
Restart: reboot, init6
Clear screen: clear, Ctrl+l

Summarize

The above is a detailed explanation of mktemp, a basic Linux command, introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Introduction to basic commands of Linux scheduled tasks (14)
  • Introduction to Linux text filtering grep basic commands (5)
  • Daily accumulation of basic Linux commands

<<:  How to change the root password of Mysql5.7.10 on MAC

>>:  Detailed explanation of vite2.0 configuration learning (typescript version)

Recommend

Docker advanced method of rapid expansion

1. Command method Run the nginx service in the cr...

How to encapsulate axios request with vue

In fact, it is very simple to encapsulate axios i...

Talking about ContentType(s) from image/x-png

This also caused the inability to upload png files...

js array entries() Get iteration method

Table of contents 1. Detailed syntax of entires()...

Vue.js front-end web page pop-up asynchronous behavior example analysis

Table of contents 1. Preface 2. Find two pop-up c...

javascript realizes 10-second countdown for payment

This article shares the specific code of javascri...

JavaScript Reflection Learning Tips

Table of contents 1. Introduction 2. Interface 3....

Detailed explanation of soft links and hard links in Linux

Table of contents 1. Basic storage of files and d...

Vue encapsulates the public function method of exporting Excel data

vue+element UI encapsulates a public function to ...

Faint: "Use web2.0 to create standard-compliant pages"

Today someone talked to me about a website develo...

JavaScript implements simple calculator function

This article shares the specific code of JavaScri...

js to realize payment countdown and return to the home page

Payment countdown to return to the home page case...

A screenshot demo based on canvas in html

Written at the beginning I remember seeing a shar...

JavaScript Snake Implementation Code

This article example shares the specific code of ...