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 strict0600permissions (only accessible by the current user):
bash
temp_file=$(mktemp /tmp/backup.XXXXXX)
temp_dir=$(mktemp -d /tmp/build.XXXXXX)