Delete a file named NUL on Windows – Step‑by‑step guide
In this article
Yes, you can delete a file called nul on Windows, but because nul is a reserved device name you must use a special path syntax or a PowerShell command that treats the name as a literal string.
What You'll Need
- Administrator access to the computer (most delete operations on system‑level locations require it).
- Command Prompt (cmd) or PowerShell – both are built into Windows.
- The exact folder path where the offending
nulfile resides.
Step‑by‑Step
- Open an elevated Command Prompt. Click the Start button, type
cmd, right‑click Command Prompt and choose Run as administrator. If you prefer PowerShell, open it the same way by typingpowershelland selecting Run as administrator.
Running with elevated privileges ensures the system will not block the delete operation because of permission issues. - Navigate to the folder that contains the
nulfile. Use thecdcommand followed by the full path, for example:cd C:\Users\YourName\Desktop\ProblemFolder
If the path contains spaces, wrap it in quotation marks. - Confirm the file really exists. Run:
dir /a "nul"
The/aswitch shows hidden and system files. You should see an entry namednulwith the attributes you expect (usuallyAfor archive). - Use the extended‑path syntax to delete. Windows blocks plain
del nulbecause it interpretsnulas the null device. Prefix the full path with\\?\to force the filesystem to treat it as a literal name:del "\\?\C:\Users\YourName\Desktop\ProblemFolder\nul"
Replace the path with your own. The surrounding quotes protect against spaces.
If the file is read‑only, add the/fflag:del /f "\\?\C:\...\nul". - Alternative: Use PowerShell's
-LiteralPathparameter. PowerShell does not interpretnulas a device when you specify-LiteralPath:Remove-Item -LiteralPath "C:\Users\YourName\Desktop\ProblemFolder\nul" -Force
The-Forceflag bypasses read‑only attributes. - Verify the file is gone. Run the same
dircommand as in step 3. No entry namednulshould appear.
If it still shows, repeat step 4 with the/fflag or double‑check the path for typos. - Optional: Use the short 8.3 filename. Some older systems still generate an 8.3 alias for
nul. Find it with:dir /x
If you see something likeNUL~1, you can delete that alias instead:del NUL~1
This works because the short name is not a reserved device name.
Note: 8.3 naming may be disabled on modern volumes, so this method is not always available. - Clean up any lingering references. Some applications cache directory listings. If you still see the file in Explorer, press F5 to refresh, or close and reopen the folder.
In rare cases, a running process may have a handle open to the file, preventing deletion. Restarting the computer releases those handles. - Close the command window. Type
exitor click the X button. Your system is now free of the problematicnulfile.
Common Mistakes
Many users try del nul directly and receive the error “The system cannot find the file specified” or “Access is denied.” This happens because Windows interprets nul as the null device, not as a regular filename. Forgetting the \\?\ prefix or the -LiteralPath switch is the most frequent oversight. Another mistake is attempting the deletion from a non‑administrator prompt; the system will silently refuse to delete files located in protected folders such as C:\Windows\System32. Finally, some people omit the surrounding quotation marks when the path contains spaces, causing the command parser to split the argument and fail.
Tips
- Always copy the full path to the clipboard before you start; paste it into the command line to avoid typing errors.
- If you suspect a process is locking the file, use
handle.exefrom Sysinternals or the built‑in Resource Monitor (typeresmon) to identify and close the handle. - When using PowerShell, the
-WhatIfparameter can show what would happen without actually deleting:Remove-Item -LiteralPath "...\nul" -WhatIf. - For batch scripts, prepend the command with
@echo offand use the extended path syntax to avoid script failures.
Troubleshooting
If the file does not delete after following the steps above, try the following checks in order of increasing impact:
- Refresh the view. Close any Explorer windows showing the folder and reopen them. Sometimes Explorer caches the listing.
- Restart the computer. A simple reboot releases file handles that may be preventing deletion.
- Run the command in Safe Mode. Boot Windows into Safe Mode (press F8 or use
bcdedit /set {default} safeboot minimal) and repeat the delete command. Minimal drivers and services run, reducing lock conflicts. - Check for hidden system attributes. If the file is marked as system or hidden, add the
/aswitch toattribto clear those flags before deletion:attrib -s -h "C:\Path\nul"
Then retry thedelcommand. - Use a third‑party file manager. Tools like Total Commander or FreeCommander respect the extended‑path syntax and sometimes succeed where Explorer fails.
- Verify the filesystem integrity. Run
chkdsk /f C:(replaceC:with the appropriate drive) to fix any corruption that could be causing phantom file entries.
Frequently Asked Questions
Why does Windows treat nul as a device name?
Historically, nul is a special file that discards all written data, similar to /dev/null on Unix. The operating system reserves the name at the kernel level, so any attempt to create a regular file with that exact name is redirected to the device.
Can I rename the nul file instead of deleting it?
Renaming faces the same reservation issue. However, using the extended‑path syntax you can rename it, e.g., ren "\\?\C:\Path\nul" newname.txt. After renaming, a normal del works.
Is the \\?\ prefix safe to use on any file?
Yes, the \\?\ prefix tells the Windows API to skip normal path parsing, allowing you to work with names that contain reserved words, trailing spaces, or Unicode characters. It works for any file, but you must supply the full absolute path.
Will deleting nul affect system functionality?
No. The reserved device nul remains available to the OS; you are only removing a stray file that mistakenly used the same name. System processes continue to use the device without interruption.
What if the file is on a network share?
The same methods apply, but you must use the UNC path, e.g., del "\\?\UNC\Server\Share\nul". Some older network devices may not support the extended syntax; in that case, map the share to a drive letter and use the local‑drive method.
Can I automate the deletion for many folders?
Yes. A simple batch loop or PowerShell script can iterate over directories and apply the del or Remove-Item -LiteralPath command with the extended path. Ensure you test on a single folder first to avoid accidental data loss.