Mktemp command in linux

mktemp Command in Linux

Introduction

Temporary files are used to temporarily store data that the operating system needs temporarily during operation and will disappear when no longer needed. they will disappear on their own after reboot.

This command in Linux allows the user to make a temporary file or directory in the tmp folder. Now we’re gonna teach you to use the mktemp command in Linux.

The syntax of the mktemp command

The syntax:

$ mktemp [option] … [template]

For example:

$ mktemp

Output:

Mktemp command in linux 1

Sponsored

You have just created a temporary file in the tmp directory. And the filename is also generated automatically.

Creating a temporary directory

To do this. Let’s add the option -d into the command:

See also  How to Downgrade the Node Version on Ubuntu?
$ mktemp -d

Output:

Mktemp command in linux 2

Name the temporary file

If you want to name the temporary file, add more than 3 X’s at the end. For example:

$ mktemp newfileXXX

Output:

Sponsored

Mktemp command in linux 3

Or you can name the temporary directory:

$ mktemp -d newdicXXX

Output:

Mktemp command in linux 4

Adding the suffix

To do this. Let’s add the option –suffix into the command. For example:

$ mktemp newfileXXX --suffix ".txt"

Output:

Mktemp command in linux 5

Conclusion

We just taught you to use the mktemp command in Linux.

Thank you for referring!

Karim buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply