How do i create temporary files in a specific location in bash script?



  • Man page for bash.
    Man page for mktemp.

    In the script set TMPDIR variable or on the command line.

    export TMPDIR=/tmp/trainer
    

    To simulate a temporary file creation. we use mktemp

     $ mktemp
    /tmp/trainer/tmp.yHANCale9O
    

    You can see the file was created in /tmp/trainer

    The same applies if creating a directory, it gets created in the TMPDIR location.

    $ mktemp -d 
    /tmp/trainer/tmp.IJYM9fjFYC
    

Log in to reply
 

© Lightnetics 2024