1830268 Members
2374 Online
110000 Solutions
New Discussion

Re: 2>&1

 
SOLVED
Go to solution
Chakravarthi
Trusted Contributor

2>&1

What is the meaning of 2>&1 and /dev/null, when do you use them

regards
chakri
6 REPLIES 6
U.SivaKumar_2
Honored Contributor

Re: 2>&1

 
Innovations are made when conventions are broken
OldSchool
Honored Contributor

Re: 2>&1

Usually used in the cron at the end of a command to not report any information to the owner as to the outcome of the shell script.

Used like this at the end:

30 00 * * * /usr/local/bin/capture > /dev/null 2>&1

Which runs the shell script clean at 12:30 AM everyday and does not report out to the console or to email whether or not it ran.

Hope this helps
Michael Schulte zur Sur
Honored Contributor

Re: 2>&1

Hi,

/dev/null is a device which if you are not intrested in the output of a command/script you can reroute the output to the so called null devices where it disappears like in a black hole.
Every process usually has three channels.
0 for standard in=stdin for input
1 for standard out=stdout for output
2 for standars error=stderr for error messages
2>&1 means reroute stdout to what is defined stdin at that moment.
ls -l /dev > /dev/null 2>&1
reroutes stdin and stderr to /dev/null
Note, some programs use stdout also for data ouput.

greetings,

Michael
Michael Schulte zur Sur
Honored Contributor
Solution

Re: 2>&1

Note, some programs use stdout also for data ouput.
well that's obvious. That should have been
Note, some programs use stderr also for data ouput.

Michael
Jeroen Peereboom
Honored Contributor

Re: 2>&1

L.S.

Michael made a small mistake:
2>&1 means reroute stdout to what is defined stdin at that moment.
Should read:
2>&1 means redirect stderr to what is defined as stdout at that moment.

JP.
Michael Schulte zur Sur
Honored Contributor

Re: 2>&1

Hi,

I must have been too tired.
correction
2>&1 means reroute stderr to what is defined stdout at that moment.
reroutes stdout and stderr to /dev/null
Note, some programs use stderr also for data ouput.

thanks JP.

Michael