Skip to main content
InterviewHubPRO
Section Overview
Q27

Question 27 of 50

Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

54%
Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)

How do you create temporary files securely with `mktemp`?

senior LevelCode Examplebash-shellAdvanced Text Processing

In Simple Words: Never hardcode /tmp/my_temp_file.txt (vulnerable to symlink race condition attacks!):

  • Use mktemp: Generates a cryptographically random, secure filename with strict 0600 permissions (only accessible by the current user):
bash
temp_file=$(mktemp /tmp/backup.XXXXXX)
temp_dir=$(mktemp -d /tmp/build.XXXXXX)