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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. gnome-terminal: command not found
  2. nitrogen: command not found
  3. register_new_matrix_user Command Examples in Linux
  4. git gc: Optimise the local repository by cleaning unnecessary files
  5. Understanding Mac file timestamps
  6. How To Send Mails To an External User With Mailx on Linux
  7. tcpdump: command not found
  8. How to Migrate CentOS/RHEL 6 iptables Rules to CentOS/RHEL 7 firewalld
  9. checkupdates : Command Examples in Linux
  10. How to Increase the File Download Size Limit in Apache

You May Also Like

Primary Sidebar

Recent Posts

  • “glab pipeline” Command Examples
  • “glab mr” Command Examples
  • “glab mr merge” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright