Categories: TutorialsUbuntu

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:

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:

$ mktemp -d

Output:

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

Or you can name the temporary directory:

$ mktemp -d newdicXXX

Output:

Adding the suffix

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

$ mktemp newfileXXX --suffix ".txt"

Output:

Conclusion

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

Thank you for referring!

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.

Ubuntu Server Admin

Recent Posts

Join Canonical in Brazil at Dell Technologies Forum São Paulo

Canonical is excited to be a part of the Dell Technologies Forum in São Paulo…

5 days ago

6 facts for CentOS users who are holding on

In 2020, it was announced that CentOS 7 would reach end of life (EoL) by…

5 days ago

What is Ubuntu used for?

The launch of Ubuntu in 2004 was a step-change for everyday users and developers everywhere.…

6 days ago

Ubuntu Weekly Newsletter Issue 862

Welcome to the Ubuntu Weekly Newsletter, Issue 862 for the week of October 13 –…

7 days ago

New Ubuntu Community Council 2024

Merlijn writes: I’m happy to announce the new 2024 Ubuntu Community Council! Heather Ellsworth (~hellsworth1)…

1 week ago