-15

I am curious to learn what is nul. It is usually used:

I also thought it was a file:

C:\Users\username> nul
Permission denied.

C:\Users\username> where nul
INFO: Could not find files for the given pattern(s).

C:\Users\username> where /r C:\ nul
INFO: Could not find files for the given pattern(s).

I have also read this great article from https://ss64.com which says:

Create empty files using the NUL device.

I don't quite understand that, however.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 2
    It probably should be spelt `nul:` but see [this](https://stackoverflow.com/q/313111/841108) – Basile Starynkevitch Dec 29 '18 at 08:33
  • 3
    Then, read Microsoft documentation, and the wikipage on [null device](https://en.wikipedia.org/wiki/Null_device). See also [this](https://stackoverflow.com/q/4507312/841108). But your question for documentation or tutorial is then off-topic here. – Basile Starynkevitch Dec 29 '18 at 08:43
  • 2
    I'm guessing that might be the same as `/dev/null` in Gnu/Linux Systems. According to the article you linked, it is indeed used to hide errors or any output you don't want on screen. – thuyein Dec 29 '18 at 09:27
  • 2
    I recommend reading the Microsoft documentation pages about [Using command redirection operators](https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490982(v=technet.10)) and [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). – Mofi Dec 29 '18 at 09:58

1 Answers1

6

Nul exists as a file in EVERY directory. It swallows anything sent to it.

Reserved names. These refer to devices eg,

copy filename con 

which copies a file to the console window.

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, 

COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, 

LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

CONIN$, CONOUT$, CONERR$

From Trouble with renaming folders and sub folders using Batch

yumyum
  • 84
  • 1
  • 2
    @double-beep nul is implemented internally as a device, but its usage is as if it were a filename. It's actually a reserved file name. E.g. `C:\Users\fred\Desktop\nul.txt` is the null device because it uses the reserved name `nul`. The name can appear *anywhere* in the file spec. – DodgyCodeException Dec 29 '18 at 09:46
  • 2
    @double-beep You aren't unable to access it. You can type `type nul` and it will print it out (i.e. it will print nothing out, since nul behaves like an empty file when you read it). The "permission denied" message means you're just not allowed to run it - it's not an executable file. – DodgyCodeException Dec 29 '18 at 11:29
  • The special behaviors of some utilities aside, NUL is a [virtual] device, not a file. The dirName\nul.ext behavior happens because nul is a reserved name in Windows (probably DOS as well), just as drive letters are reserved (try `cd /d c:\ & echo test > c:.txt` in an elevated console window, then look for a '.txt' file in C:\). So when you reference anything named 'nul' in Windows, it maps to the nul device, just as anything named ': ' maps to the device named 'driveLetter'. It is not an extra-specially hidden file in every directory. It's a reserved name. – jwdonahue Dec 29 '18 at 23:51