Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a /dev/null on Windows?

Tags:

windows

What is the equivalent of /dev/null on Windows?

like image 715
Ove S Avatar asked Nov 23 '08 23:11

Ove S


People also ask

How do I access dev null?

You write to /dev/null every time you use it in a command such as touch file 2> /dev/null. You read from /dev/null every time you empty an existing file using a command such as cat /dev/null > bigfile or just > bigfile. Because of the file's nature, you can't change it in any way; you can only use it.

How do I redirect to null in Windows?

The > NUL redirects the stdout to the NUL device (the equivalent of /dev/null ) and the 2 >&1 also redirects the stderr to stdout so that nothing is output to the console. I wrote this up so that I remembered what I had done (and why) – if this helps you, that's great!

What is Windows NUL?

The null device is a special file that discards all data written to it, but reports that the write operation succeeded. Nul is often used to hide the output (or error output) of a command. It is called NUL rather than NULL for historical reasons, many other devices have 3 character names: AUX, PRN, CON, etc.

What kind of device is dev null?

/dev/null is a null device–a special type of virtual device. It is present in every Linux system, and the purpose of this device is to discard anything sent to it and read the End of File (EOF). Most virtual devices are used to read data; however, /dev/null is unique since it is used to suppress any data written to it.


1 Answers

I think you want NUL, at least within a command prompt or batch files.

For example:

type c:\autoexec.bat > NUL 

doesn't create a file.

(I believe the same is true if you try to create a file programmatically, but I haven't tried it.)

In PowerShell, you want $null:

echo 1 > $null 
like image 98
Jon Skeet Avatar answered Sep 18 '22 07:09

Jon Skeet