What does /dev/null do in the command line?

Ortiz34

New Member
Credits
24
I'm learning to do some CTFs. I noticed that the writer always type this command line
find / -name [filename.txt] 2>/dev/null

I understand what the "find" command line does, but why would he/she add "2>/dev/null"
 


f33dm3bits

Gold Member
Gold Supporter
Credits
7,490
2 is a file descriptor for stderr and > is redirection. So what this basically means is that all the errors that come from the find command are being redirected to /dev/null meaning they won't be displayed in the output.
 

JasKinasis

Well-Known Member
Credits
4,005
"2> /dev/null" at the end of a command redirects error messages to /dev/null instead of to stdout.
That way you only see output from the command without seeing any error messages.

/dev/null is also known as the bit-bucket.
When anything is written, or redirected to /dev/null - it is effectively lost.

/dev/null can also be used as an input device, which will provide a stream of zeros.
So you could also completely wipe a usb drive by using:
Bash:
dd if=/dev/null of=/dev/sdx bs=1M
Where /dev/sdx is the device node for the drive in /dev.

Edit: Use the above command extremely carefully! Or better still don’t use it at all!! It’s only there as an example of another practical usage of /dev/null. dd is nicknamed the data destroyer for very good reasons. If you don’t know what you’re doing with it, you can completely bork things!!
 
Last edited:

Ortiz34

New Member
Credits
24
"2> /dev/null" at the end of a command redirects error messages to /dev/null instead of to stdout.
That way you only see output from the command without seeing any error messages.

/dev/null is also known as the bit-bucket.
When anything is written, or redirected to /dev/null - it is effectively lost.

/dev/null can also be used as an input device, which will provide a stream of zeros.
So you could also completely wipe a usb drive by using:
Bash:
dd if=/dev/null of=/dev/sdx bs=1M
Where /dev/sdx is the device node for the drive in /dev.

Edit: Use the above command extremely carefully! Or better still don’t use it at all!! It’s only there as an example of another practical usage of /dev/null. dd is nicknamed the data destroyer for very good reasons. If you don’t know what you’re doing with it, you can completely bork things!!
lol thanks for the warning. I really appreciate your post. That was valuable to know. I'll def be careful of using dev/null and using dd (data destroyer). I'm currently using virtual machines for Linux practices.
 



Top