65

I have a Windows XP box (NTFS filesystem) on which I found a file named NUL. I have not been able to remove this file in any usual way. The file appears to be owned by Administrator in the SYSTEM group, unlike any other file in the same directory (the other files are owned by my user id).

How do I get rid of this file? Where did it come from?

4
  • 3
    NUL is a system reserved word; see this Wikipedia article. A file named NUL should never exist on the filesystem; this may be caused by buggy software. You may be able to remove it using the DELETE command using Command Prompt.
    – bwDraco
    May 11, 2011 at 17:30
  • 11
    @DragonLord: The filesystem doesn't have a problem with such names; for example, you can create such files within a POSIX environment. (One can find aux.c and similar names in software source code.) It's purely the Win32 API that manages these "device names". May 12, 2011 at 5:17
  • 1
    The same applies to CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, and CLOCK$ plus a few others - see en.wikipedia.org/wiki/…
    – robocat
    Apr 30, 2015 at 1:38
  • 2
    Cygwin creates (or used to) a file called "nul", usually seen in "C:\cygwin\dev\nul". This is the one that I hit once every few years, I Google, and I'm brought back (again) to this question. May 15, 2017 at 19:35

6 Answers 6

113

Try

Del \\?\C:\My\Path\NUL

in the command prompt.

See this Microsoft Support article for details: You cannot delete a file or a folder on an NTFS file system volume, under "Cause 5: The file name includes a reserved name in the Win32 name space".

6
  • 1
    Thanks! That worked! Also, thanks for the great reference to the authoritative documentation. I found something in a web search that was very similar, but did not work. That suggestion had a . in place of the ?. May 11, 2011 at 20:12
  • 1
    @Greg: Sure! The documentation was @DragonLord's help. :-) And yeah, putting . instead of ? doesn't quite do the same thing -- the question mark prevents further processing by the subsystem, whereas the period means "the current machine"... not quite the same thing, although it's definitely confusing. :)
    – user541686
    May 11, 2011 at 20:23
  • 1
    I'm not sure it actually means that. The \\.\ prefix is for the device namespace, but there is no explicit mention that . has the same meaning ("current X") as it does for directory names. May 12, 2011 at 5:15
  • 5
    As an alternative to above solution if your working directory is already the directory with the nul file, you can: del "\\?\%CD%\nul" The %CD% part is expanded to the working directory and the double quotation marks (") make it all handle also pathnames with "odd" symbols, e.g. "\\?\C:\path,with\comma\nul".
    – HenrikB
    Sep 7, 2013 at 15:09
  • 1
    It did not not seem to be effective from powershell or an administratively elevated prompt in my environment, but worked effectively in a standard terminal.
    – JustinC
    Sep 26, 2013 at 21:43
19

Alternatively if you have Cygwin installed, you may want to know, that it has no problem with such files or folders. Particularly,

rm -r /cygdrive/c/path/to/the/file/or/folder/you/want/to/delete

typed in the Cygwin terminal deletes the file or folder named nul or a folder, containing it. This is also applicable to other special file names such as CON, PRN, AUX, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8.

3
  • 4
    also works with git bash
    – c33s
    Sep 20, 2016 at 10:24
  • 1
    If you have installed Git then you've got the GNU rm command so you don't need cygwin. Assuming you add the GNU tools bin directory to your PATH you can use all the GNU goodies from cmd.
    – icc97
    Nov 27, 2017 at 23:33
  • Thanks for posting this, I mainly use cygwin so it's much more convenient for me to use than the CMD way (which is also perfectly valid, ofc). Aug 17, 2023 at 14:18
11

I'm adding this here because it is high in the google results and I had a similar issue for a folder named NUL. Unfortunately the above fixes didnt help. Neither did a ton of other stuff I looked at.

I tried rmdir\\?\C:\My\Path\NUL and rmdir\\.\C:\My\Path\NUL without any success and also tried several commands using bash from my SourceTree installation. No joy.

In the end I used DIR /X /A from cmd to list the short names in the parent directory. This returned NUL~1 for my NUL folder.

This was then used in the standard command rmdir /s NUL~1 and finally fixed the problem.

1
  • 2
    Hmm, that's pretty clever using the short name to bypass the special name.
    – SamB
    Jun 18, 2017 at 15:38
6

If you have Git for Windows Installed do the following

  1. Open the directory containing the files you want to remove
  2. Left Click and select Git Bash Here
  3. Type rm nul.json at the command prompt and hit ENTER, the file now should be removed.

run Git Bash Here

NOTE: These screenshots show the removal of file nul.topo.json which is another file that I could not removed with a simple delete.

after command execution

1
  • rm NUL if your file is named NUL like the OP.
    – wphampton
    Jun 15, 2021 at 12:59
1

If you have PowerShell 6.1.0 (Sep 2018) or higher:

https://github.com/PowerShell/PowerShell/releases/tag/v6.1.0

you can do something like this:

Remove-Item -LiteralPath \\?\C:\NUL

Another option is this Go program:

package main
import "os"
func main() {
   os.Remove(`\\?\C:\NUL`)
}
0

Cygwin, git bash or WSL (for Windows 10)

rm PREFIX/c/path/to/the/file/or/folder/you/want/to/delete

PREFIX="/cygdrive" (Cygwin)

2. PREFIX="" (git bash)

3. PREFIX="/mnt" (WSL)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .