Marcio Cunha

How to clean temporary files in Windows using CMD step by step

Learn how to free up disk space in Windows quickly using native commands in the Command Prompt without installing third-party software.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • Continuous use of Windows accumulates gigabytes of temporary files in hidden folders that slow down the system.
  • The Command Prompt (CMD) allows you to delete these residual files natively without needing external software.
  • Correctly executing commands like rd and del eliminates digital clutter while keeping the operating system stable.
  • Periodic cleaning routines prevent chronic sluggishness and help optimize SSD or HDD storage usage.
  • Similar storage optimization procedures also complement other common operating system maintenance tasks.

Why does Windows accumulate so many temporary files?

As you browse the internet, install programs, or open documents, the operating system generates invisible records called temporary files. In practice, this means the computer stores snippets of data that were only needed at that exact moment but end up forgotten on your hard drive or SSD. Over the months, this mass of residual data consumes dozens of gigabytes, reducing useful space and making the computer visibly slower. If you have ever needed to manage disk space in Windows due to overcrowded partitions, you know how much this digital clutter gets in the way.

Many users turn to third-party programs to handle this cleanup, but Windows itself has powerful tools built right into its command-line interface. Using the Command Prompt (CMD) is a fast, safe alternative that avoids installing questionable apps found on the web. Furthermore, understanding how to delete these directories manually gives you total control over what is being removed from your machine.

Where are temporary files located on your computer?

The operating system stores this data in specific locations known as temporary folders. There are two main ones: one tailored for the current user and another shared across the entire system. The user folder is hidden inside the login profile, while the global system folder resides directly in the root of the Windows directory. When applications crash or close abruptly, they tend to leave corrupted traces in these exact spots.

Before running any mass deletion commands, it is important to know that some files in use at the moment cannot be deleted. The operating system protects these active records to prevent blue screens or operational failures. For anyone dealing with corporate networks or flushing DNS cache in Windows, keeping the environment clean prevents a series of parallel performance and connectivity conflicts.

How to open the Command Prompt with administrator privileges

To successfully delete files belonging to protected system folders, you need to run CMD with elevated permissions. Without this, Windows will block most deletions by displaying access denied messages. The procedure to open this special terminal is quite simple and straightforward on any recent version of the operating system.

  1. Press the Windows + R keys on your keyboard to open the Run dialog box.
  2. Type the word cmd into the text field that appears on the screen.
  3. Simultaneously press the Ctrl + Shift + Enter keys to open the Command Prompt with administrative privileges.

Step-by-step guide to clear the user temporary directory

The first folder we are going to empty is the temporary folder for the currently logged-in user. This folder usually accumulates old installers, browser caches, and leftovers from applications you opened recently. To access and clean this location directly through the terminal, we use commands that navigate the directory structure and remove content recursively.

  1. Open CMD as an administrator as explained in the previous step.
  2. Type the command cd /d %TEMP% and press Enter to navigate to the user's temporary folder.
  3. Execute the complete cleanup by typing the command
    del /s /q /f *.*
    and press Enter.

How to remove global system temporary files

In addition to the user folder, Windows maintains a global directory of temporary files located at the system root. This location stores data generated by background services and operating system updates. The procedure to clean this second folder follows the same logic as the previous step, requiring only a change in the terminal path.

  1. Open the Command Prompt with administrative privileges.
  2. Type the command cd /d C: emp or access the default Windows folder by typing cd /d C:\|$Windows.~BT if there are remnants of past upgrades.
  3. Execute the deletion of residual files by typing
    rd /s /q .
    and press Enter to confirm.

Essential precautions when deleting data via command line

Using the Command Prompt requires extra attention because the terminal does not display that classic confirmation box with the traditional recycling bin. In practice, this means everything you delete through it is removed permanently and immediately, without any simple recovery option. Never type commands in system folders like System32 unless you know exactly what you are doing.

If messages appear during command execution stating that some files are in use, do not worry. This happens because an open software or Windows service has that file locked at the moment. Simply ignore these warnings, close background programs, and restart your computer as soon as the cleanup finishes to ensure the system starts fresh and fully optimized. To explore these architectural concepts further in production, see our related technical analysis on How to test an ATX power supply with a resistor on bench.

Final considerations on storage maintenance

Maintaining the habit of cleaning temporary files periodically prevents unnecessary wear on your storage and improves overall computer response times. Although Windows has graphical tools like Disk Cleanup, mastering CMD speeds up the process and puts technical control right in your hands. Integrating this simple maintenance routine into your daily life guarantees a fluid system ready for any task.