Posts Tagged ‘redirection /bin/sh /bin/ksh /bin/bash’

/dev/null – What is this?

Friday, January 30th, 2009

On Unix and Linux systems you’ll have a device driver called /dev/null that is curious to some, and baffling to others.

Think of this device as a black hole, in that whatever you send to it is never seen again.  Any data sent to this device uses no memory nor hard disk.  It is just gone.

So, 

cat /etc/motd > /dev/null

Which reads “output /etc/motd file data to /dev/null”, will show nothing to the screen, nor will it create a new file called /dev/null and have data stored in it.

This seems useless at first, but can be very useful when you get a lot of garbage messages or warnings from when you compile a program, or run some software.

cc file.c > goodoutput 2> /dev/null

The above is read as follows: 

1) Compile file.c

2) Send good output to a file called goodoutput

3) Send errors and warning messages to /dev/null

Later I’ll explain why it is shown as 2>

In the meantime to learn more run

man bash

or

man sh

and search on REDIRECTION