1

If nul can never be a file in Windows, what if it a file called "nul" was created in all the directorys using a OS that doesn't have the same rules for nul. Would data be written to nul if for example 'echo 1234>nul' was performed in CMD or would it be discarded?

barry john
  • 13
  • 2
  • The accepted answer helps future visitors to quickly navigate to useful information. In this case I would recommend accepting [this answer](http://stackoverflow.com/a/37927677/1889329) instead. Make sure to read [What should I do when someone answers my question?](http://stackoverflow.com/help/someone-answers) as well as [What does it mean when an answer is "accepted"?](http://stackoverflow.com/help/accepted-answer). – IInspectable Jun 20 '16 at 17:07
  • There should never, ever be a file named 'NUL'. However, sometimes things happen. In an Oracle environment, I had a file named 'NUL.LST'. 'http://stackoverflow.com/questions/26186852/how-to-delete-nul-lst-file – lit Jun 20 '16 at 17:30

2 Answers2

8

if for example 'echo 1234>nul' was performed in CMD or would it be discarded?

It would be discarded.

Note the following example which creates a file called nul then calls echo 5678>nul. The existing file nul is not changed.

C:\temp>echo 1234>\\?\%cd%\nul

C:\temp>dir /b /a-d
nul

C:\temp>type \\?\%cd%\nul
1234

C:\temp>echo 5678>nul

C:\temp>type \\?\%cd%\nul
1234

C:\temp>del \\?\%cd%\nul

C:\temp>

For details about the \\?\ syntax see Win32 File Namespaces.

dxiv
  • 16,984
  • 2
  • 27
  • 49
0

Nul is not a reference to a file, it is part of Windows and when >nul is performed, it isn't writing it the the file nul, but instead it's just being ignored