1

Previously mktemp used to create files in /tmp. Today I noticed that mktemp is creating file in $PWD rather than in /tmp?

Did I change something inadvertently? Any suggestions to fix this?


Note:

I am able to do: ls /tmp

$ mktemp --version
mktemp (GNU coreutils) 8.30
$ echo $TMPDIR

$
Porcupine
  • 1,680
  • 2
  • 19
  • 45

1 Answers1

5

For the GNU Coreutils implementation, there is a difference depending on whether an explicit TEMPLATE is provided on the command line or not. As per the man page:

SYNOPSIS
      mktemp [OPTION]... [TEMPLATE]
If TEMPLATE is not specified, use `tmp.XXXXXXXXXX`, and `--tmpdir` is implied.

(note the --tmpdir is implied); where

   -p DIR, --tmpdir[=DIR]
          interpret TEMPLATE relative to DIR; if DIR is not specified, use $TMPDIR 
          if set, else /tmp.

So

$ mktemp foo.XXX
foo.eWT

uses the current directory, whereas plain

$ mktemp
/tmp/tmp.hrY7qNWWty

defaults to /tmp (since --tmpdir is implied, but no $TMPDIR set).

steeldriver
  • 78,509
  • 12
  • 109
  • 152