mktemp - macOS
Overview
mktemp creates a temporary file or directory. It assigns a unique filename or directory path for temporary usage. The created temporary file or directory is automatically deleted when the system restarts or the user logs out.
Syntax
mktemp [-d | -p prefix] [template]
Options/Flags
- -d: Creates a temporary directory instead of a file.
- -p prefix: Specifies a prefix for the temporary file or directory name.
Examples
- Create a temporary file:
mktemp
- Create a temporary directory:
mktemp -d
- Create a temporary file with a specific prefix:
mktemp -p myfile
Common Issues
- Error: File exists: The temporary file or directory already exists. Try again with a different template.
- Error: Permission denied: You do not have permission to create a file or directory in the specified location. Try creating it in a different location where you have write permissions.
Integration
mktemp can be used in shell scripts to create temporary files or directories for temporary data storage or processing. It can also be used in combination with other commands that require temporary storage, such as ffmpeg or tar.
Related Commands
- touch
- rm
- mkdir
- rmdir