Pages: Welcome | Projects

Temporary

2015/7/31
Tags: [ Ideas ] [ shell ]

How often do you need to use a temporary file, or create a scratch directory you will remove later?

It happens to me a lot. So I use a simple script I'll share here:

#!/bin/sh

tmpdir=`mktemp -d`
(
    cd $tmpdir
    exec $SHELL
)
rm -rvf $tmpdir

When invoked, it will create a temporary directory (according to what your OS believes is a good position) and will cd into it. After you are done and exit from the inner shell the directory is removed, so you don't put garbage on your disk.