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!

Ubuntu Server Admin

Recent Posts

From sales development to renewals: Mariam Tawakol’s career progression at Canonical

Career progression doesn’t follow a single path – and at Canonical, we embrace that. Our…

9 hours ago

In pursuit of quality: UX for documentation authors

Canonical’s Platform Engineering team has been hard at work crafting documentation in Rockcraft and Charmcraft…

9 hours ago

Ubuntu 24.10 (Oracular Oriole) reached End of Life on 10th July 2025

This is a follow-up to the End of Life warning sent earlier to confirm that…

1 day ago

Canonical announces Charmed Feast: A production-grade feature store for your open source MLOps stack

July 10, 2025: Today, Canonical announced the release of Charmed Feast, an enterprise solution for…

1 day ago

Ubuntu Adding NVIDIA 575 Driver Support for 24.04 & 22.04 LTS

For NVIDIA users, the latest 575 series driver will be available soon in Ubuntu repository.…

2 days ago

Amarok Released 3.3 with Qt6/KF6 Port & GStreamer Backend

Amarok, the free open-source KDE music player, released new 3.3 version on Tuesday, named “Far…

2 days ago