# Cleaning Up: trap and mktemp

mktemp makes a temporary file or folder with a name no other file has, and trap '...' EXIT runs cleanup however a script ends, Ctrl+C included, so a script that works in a scratch file never leaves half-finished work behind.

![Cheat sheet for the lesson Cleaning Up: trap and mktemp: mktemp makes a temporary file or folder with a name no other file has, and trap '...' EXIT runs cleanup however a script ends, Ctrl+C included, so a script that works in a scratch file never leaves half-finished work behind.](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/57b54670069047f19eb51a9f3878342b.webp)

- Category: Bash
- Level: Freelancer
- Tags: linux, mktemp, signal, temporary-file, trap, unix
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/bash-trap-and-temp-files-cheat-sheet
