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

AI in 2025: is it an agentic year?

2024 was the GenAI year. With new and more performant LLMs and a higher number…

3 hours ago

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

1 day ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

2 days ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago