Temporary files

Also known as: temp files

On this page 7

Temporary files, often called temp files, are files that an operating system or application creates to hold intermediate data for a limited time, such as extracted installer packages, print spool jobs, unsaved document states or download fragments. Within OS updates & maintenance, they matter because update engines stage large payloads in temporary locations, and because orphaned temporary files accumulate when programs crash or fail to clean up after themselves.

In desktop operating systems, temporary storage is a deliberate design feature rather than an accident. It lets software work with data that does not fit in memory, protects against data loss during long operations and isolates scratch work from permanent user content. The cost is disk space consumption and, occasionally, privacy and security exposure when sensitive data lingers longer than intended.

How operating systems create and manage temporary files

An operating system provides designated temporary directories and APIs that return a unique file name, so that programs do not collide when they write scratch data at the same moment. On Windows, the GetTempPath and GetTempFileName functions resolve the per-user folder stored in the %TEMP% and %TMP% environment variables. On Linux and macOS, the POSIX functions mkstemp and tmpfile create files atomically with restrictive permissions to prevent other users from hijacking them.

The lifecycle of a temporary file follows a simple pattern: create, write, read back or transform, then delete. Well-written software deletes the file explicitly or opens it with a delete-on-close flag, such as FILE_FLAG_DELETE_ON_CLOSE on Windows or the O_TMPFILE option on Linux, which creates an unnamed file that vanishes automatically. Problems begin when a process terminates abnormally, because the cleanup code never runs and the file remains on disk indefinitely.

The following table lists the standard temporary locations on the three major desktop platforms and the policies that govern them.

PlatformTypical locationScopeAutomatic cleanup
Windows user temp%LOCALAPPDATA%\TempPer userStorage Sense, if enabled
Windows system tempC:\Windows\TempSystem servicesDisk Cleanup or Storage Sense
Linux /tmp/tmp, often tmpfs in RAMAll users, sticky bitCleared at boot or by systemd-tmpfiles
Linux /var/tmp/var/tmp on diskAll users, persistentAging rules, often 30 days
macOS per-user temp/private/var/folders/…Per userPeriodic system maintenance and reboot
Default temporary locations by platform

Types of temporary files and their purpose

Temporary data is not a single category. It ranges from transient scratch files that live for milliseconds to semi-persistent caches that survive reboots by design. Distinguishing these types is essential before deleting anything, because some caches rebuild cheaply while others hold data that a running process still needs.

TypeCreated byTypical sizeSafe to delete
Installer extraction filesSetup programs and update agentsTens of MB to several GBYes, after installation completes
Update staging payloadsWindows Update, softwareupdated1 to 10 GB or moreOnly when no update is pending
Application autosave filesOffice suites, editorsKB to MBNo, while the document is open
Print spool filesPrint spooler serviceKB to hundreds of MBYes, when the queue is empty
Browser and thumbnail cachesBrowsers, file managersHundreds of MBYes, they regenerate
Crash and log fragmentsError reporting servicesMB to GBYes, after diagnosis
Common kinds of temporary data

Related artifacts such as a crash dump or a pagefile are sometimes grouped with temporary data in cleanup tools, but they serve different purposes. A crash dump is diagnostic evidence, and the page file is virtual memory backing store that the kernel manages directly; neither should be deleted manually through the temporary folder.

Temporary files during OS updates

Operating system updates are among the largest producers of temporary data. An OS update typically downloads compressed packages, expands them into a staging area, verifies digital signatures and then applies changes during one or more reboots. Windows uses the SoftwareDistribution\Download folder and the component store, while macOS stages updates in protected system volumes before the restart.

An in-place upgrade to a new major release can temporarily require 20 GB or more of free space, partly for the new image and partly for a rollback copy of the previous installation, such as the Windows.old folder. Removing these files frees significant space but also removes the ability to roll back within the usual 10-day window. For this reason, cleaning update leftovers belongs after the update has been confirmed stable, not before.

Insufficient free space is a frequent cause of failed updates. When the system drive is nearly full, the update agent cannot stage payloads and reports cryptic error codes. Clearing obsolete temporary files is therefore a standard first step in patch management troubleshooting, alongside checking driver compatibility and pending reboots.

Cleaning temporary files safely

Safe cleanup relies on built-in maintenance tools rather than manual deletion of system folders. These tools understand which files are locked, which belong to pending operations and which can be removed without side effects. Manual deletion remains acceptable for the per-user temp folder, provided that files currently in use are skipped.

The decision table below matches common situations with the recommended cleanup approach.

SituationRecommended methodReason
Routine monthly maintenanceStorage Sense or Disk CleanupHandles locks and age thresholds automatically
Failed update due to spaceClean update files, then retryRemoves stale payloads blocking staging
After a confirmed major upgradeRemove previous installation filesReclaims many GB once rollback is unnecessary
Linux server with full /tmpConfigure systemd-tmpfiles agingPrevents recurrence instead of one-time deletion
Suspected malware in tempSecurity scan before deletionPreserves evidence and finds persistence
Choosing a cleanup method
  • Close applications before cleaning, because open files are locked and partially written data may be lost.
  • Never delete the folder itself or redirect %TEMP% to a slow or removable drive.
  • Schedule cleanup after a reboot, when most locks are released and pending operations have finished.

Risks, security issues and common mistakes

Temporary files create security exposure when they hold sensitive content in readable form. Decrypted documents, credentials embedded in installer logs or exported reports may remain in temp folders long after use. On shared Linux systems, predictable file names enable symlink race attacks, which is why secure APIs generate random names and set the sticky bit on /tmp.

Malware also exploits these locations because they are writable by standard users and rarely monitored. Many security policies therefore block execution from temp directories, using application control rules that deny launching binaries from %TEMP% paths.

SymptomLikely causeFix
Temp folder grows to many GBCrashed programs leaving orphansEnable automatic cleanup with age threshold
Update fails with space errorStale staging payloadsRun update cleanup and retry
Application cannot save or installTemp path invalid or fullRestore default environment variables
Lost unsaved work after cleanupAutosave files deleted while openClose applications before cleaning
Typical problems and fixes

A common misconception holds that deleting temporary files improves performance directly. In practice, the benefit is mostly reclaimed disk space; speed improves only when a nearly full drive was causing fragmentation, failed writes or update loops.

In everyday language

Temporary files are like the scrap paper a person uses while solving a math problem. The computer writes down notes in the middle of a task, such as unpacking a program or preparing a document for printing, and is supposed to throw them away afterward.

Sometimes a program closes unexpectedly and forgets to tidy up. Over months, these forgotten notes pile up and take space on the drive. Cleaning them with the built-in tools is safe and frees space, but it rarely makes the computer noticeably faster on its own.

Seen in the real world

An IT technician at a small accounting office notices that a laptop with a 128 GB system drive repeatedly fails to install a feature update. The drive shows only 4 GB free. Inspection reveals about 9 GB of orphaned files in the user temp folder, left by an accounting package that crashed during several export jobs, plus 6 GB of outdated update payloads.

The technician closes all applications, runs the built-in cleanup tool with update files selected and enables automatic removal of temp files older than 14 days. Free space rises to 19 GB, the feature update installs successfully on the next attempt, and the recurring problem disappears because the cleanup schedule now prevents the folder from growing unchecked.