• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

mktemp Command Examples in Linux

by Deepika

“mktemp” is a command-line utility in Linux and Unix-like systems used to create temporary files or directories. The primary purpose of “mktemp” is to provide a convenient and safe way to create temporary files in shell scripts and other programs, to avoid potential race conditions and security issues that can arise when using simple file names based on the current time or process ID.

The “mktemp” command takes a template string as an argument, which specifies the desired file name or directory name pattern. The template string can contain X’s, which are replaced with unique characters to create a unique file or directory name. For example, if you use the template “/tmp/tmp.XXXXXX”, “mktemp” will replace the X’s with a unique string of characters to create a file or directory such as “/tmp/tmp.z48xd3”.

The “mktemp” command also provides options to control the permissions of the created file or directory, to specify the directory where the temporary file should be created, and to ensure that the file or directory is readable and writable only by the user who created it.

In general, “mktemp” is a useful tool for shell script developers and system administrators, as it provides a convenient and secure way to create temporary files and directories in scripts and other programs.

mktemp Command Examples

1. Create an empty temporary file and print the absolute path to it:

# mktemp

2. Create an empty temporary file with a given suffix and print the absolute path to file:

# mktemp --suffix ".ext"

3. Create a temporary directory and print the absolute path to it:

# mktemp -d

Filed Under: Linux

Some more articles you might also be interested in …

  1. hardinfo Command Examples in Linux
  2. Integrate Linux Servers with Active Directory using Samba, Winbind, and Kerberos
  3. How to install zip/unzip package in Linux CentOS/RHEL 7 and 8
  4. chgrp: command not found
  5. How to prevent SSH connections from disconnecting due to inactivity when using MobaXterm
  6. CentOS / RHEL 6 : How to force a NTP sync with the NTP server(s)
  7. mkfs.xfs: command not found
  8. etckeeper Command Examples in Linux
  9. How to Create a Bridge Interface Using nmcli in CentOS/RHEL 7 and 8
  10. lvmconf Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright