Why are there both TMP and TEMP environment variables? (2015)

Published: (May 2, 2026 at 04:23 AM EDT)
2 min read

Source: Hacker News

History

CP/M (1973)

The original micro‑computer operating system, CP/M, had no environment variables. Consequently, there was neither a TMP nor a TEMP variable. Programs that needed a temporary‑file location had to rely on program‑specific configuration, such as patching a byte in the executable to indicate the drive letter.

MS‑DOS (1981)

When the 8086 processor and MS‑DOS arrived, the design was heavily inspired by CP/M. One of the first additions MS‑DOS made beyond CP/M compatibility was environment variables. Early MS‑DOS programs, being ports of CP/M software, ignored these variables.

As native MS‑DOS applications emerged, developers began using environment variables for configuration. Two variables—TEMP and TMP—became the de‑facto standards for indicating a temporary‑file directory.

MS‑DOS 2.0 introduced piping, which MS‑DOS simulated by writing the first program’s output to a temporary file and then feeding that file to the second program. For this purpose the OS used the TEMP variable to determine where to create those temporary files.

Different programs chose different preferences:

  • DISKCOPY and EDIT looked for TEMP first, then TMP.
  • The Windows API function GetTempFileName checks TMP before TEMP.

Windows

Windows inherited the dual‑variable situation. The original authors of GetTempFileName preferred TMP, so most Windows programs that rely on this API will use the directory specified by TMP unless they explicitly check TEMP.

When you open the Environment Variables dialog in Windows, you will still see both TMP and TEMP listed, each potentially pointing to different locations. The variable actually used depends on the program’s implementation.

Practical Takeaway

  • The directory used for temporary files is program‑dependent.
  • If you want consistent behavior across most Windows applications, ensure that both TMP and TEMP point to the same folder.
  • For legacy MS‑DOS utilities, TEMP may be the preferred variable.

References

0 views
Back to Blog

Related posts

Read more »

MVC Architecture Flow in Spring Boot

!Cover image for MVC Architecture Flow in Spring Boothttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2F...