Clear temporary scratch files on HPC
Unix-like HPC systems often have shared temporary scratch directories mapped by environment variable $TMPDIR
to a directory like “/scratch” or “/tmp”.
$TMPDIR
may be used for temporary files during build or computation.
$TMPDIR
is often shared among all users with no expectation of preservation or backup.
If user files are left in $TMPDIR
, the HPC system may email a periodic alert to the user.
If the user determines that $TMPDIR
files aren’t needed after the HPC batch job completes, one can clear $TMPDIR
files with a command near the end of the batch job script.
Carefully consider whether this is appropriate for the specific use case, as the scratch files will be permanently deleted.
rm -r -i $TMPDIR 2>/dev/null
Verify that deletes only the user’s files, as each user’s files have write permissions only for their own files. Once this is established, to use this command in batch scripts replace the “-i” with “-f” to make it non-interactive.