What is the equivalent of /dev/null
on Windows?
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.
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!
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.
/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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With