The trap command is useful when you want your shell program to automatically remove any temporary files that are created when the shell script runs. The trap command is a basic, but a very beneficial tool. If the script generates temporary files, like a simple script that changes FOO for BAR in entirely files in the existing directory, /tmp file will be clean when you exit the script.