Recall & Review
beginner
What is the purpose of the
mktemp command in bash scripting?The
mktemp command creates a unique temporary file or directory safely, avoiding name conflicts and security issues.Click to reveal answer
beginner
How does
mktemp ensure the temporary file name is unique?mktemp generates a random string in the file name template, replacing placeholders like XXXXXX to create a unique name.Click to reveal answer
beginner
Write a simple
mktemp command to create a temporary file with prefix tempfile_.Use:
mktemp tempfile_XXXXXX. This creates a file like /tmp/tempfile_a1b2c3 in the system's temporary directory (usually /tmp).Click to reveal answer
intermediate
Why should you use
mktemp instead of manually creating temporary files with fixed names?Manually creating fixed-name temp files risks overwriting files or security issues.
mktemp avoids these by making unique, safe names.Click to reveal answer
beginner
How can you create a temporary directory using
mktemp?Use
mktemp -d to create a unique temporary directory instead of a file.Click to reveal answer
What does the
XXXXXX part in the mktemp template represent?✗ Incorrect
The
XXXXXX is replaced by random characters to ensure the filename is unique.Which option creates a temporary directory with
mktemp?✗ Incorrect
The
-d option tells mktemp to create a directory instead of a file.Why is using
mktemp safer than creating temp files with fixed names?✗ Incorrect
mktemp avoids overwriting existing files and reduces security risks by generating unique names.What will
mktemp tempfile_XXXXXX do?✗ Incorrect
The
XXXXXX is replaced with random characters, making a unique filename starting with 'tempfile_'.If you want to create a temporary file in the system temp directory, which option do you use?
✗ Incorrect
The
-p option specifies the directory where the temp file will be created.Explain how to safely create and use a temporary file in a bash script using
mktemp.Think about creating, using, and cleaning up the temp file.
You got /4 concepts.
Describe the security benefits of using
mktemp over fixed temporary file names.Consider what can go wrong with fixed names.
You got /4 concepts.