Challenge - 5 Problems
Temporary File Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this mktemp command?
Consider the following command run in a bash shell:
What does this command output?
mktemp /tmp/tempfile.XXXXXXWhat does this command output?
Bash Scripting
mktemp /tmp/tempfile.XXXXXX
Attempts:
2 left
💡 Hint
mktemp replaces the XXXXXX with random characters to create a unique filename.
✗ Incorrect
The mktemp command creates a unique temporary file or directory. When given a template with Xs, it replaces them with random characters to avoid name collisions.
💻 Command Output
intermediate2:00remaining
What error does this mktemp command produce?
What error message will this command produce?
Note: The template does not contain any 'X' characters.
mktemp /tmp/tempfileNote: The template does not contain any 'X' characters.
Bash Scripting
mktemp /tmp/tempfile
Attempts:
2 left
💡 Hint
mktemp requires at least 3 'X' characters in the template to replace.
✗ Incorrect
The mktemp command expects a template with at least 3 'X' characters to generate a unique name. Without them, it throws an error about too few X's.
🔧 Debug
advanced2:00remaining
Why does this mktemp command fail to create a file?
Given this command:
It fails with an error 'cannot create directory'. What is the most likely reason?
mktemp -d /tmp/mydir.XXXXXXIt fails with an error 'cannot create directory'. What is the most likely reason?
Bash Scripting
mktemp -d /tmp/mydir.XXXXXX
Attempts:
2 left
💡 Hint
Check if the directory where you want to create the temp directory exists and is writable.
✗ Incorrect
The -d option tells mktemp to create a directory. If /tmp does not exist or you lack permissions, mktemp cannot create the directory and fails.
🚀 Application
advanced2:00remaining
Which script snippet safely creates and cleans up a temporary file?
You want to create a temporary file, write 'Hello' into it, then delete it after use. Which snippet does this correctly?
Attempts:
2 left
💡 Hint
Remember to capture the output of mktemp in a variable and quote variables when used.
✗ Incorrect
Option A correctly captures the temporary filename in a variable, uses quotes to handle spaces, writes to the file, reads it, then removes it. Others either miss command substitution or quoting.
🧠 Conceptual
expert2:00remaining
Why is mktemp preferred over manual temp file naming?
Why should scripts use mktemp to create temporary files instead of manually naming files like /tmp/tempfile.txt?
Attempts:
2 left
💡 Hint
Think about what happens if two scripts use the same temp filename.
✗ Incorrect
mktemp creates unique filenames safely, preventing conflicts and security issues like race conditions. Manual naming risks overwriting files or security holes.