Operating System - Linux
1753876 Members
7328 Online
108809 Solutions
New Discussion

2>&1 (what is the meaning?) <:0 /

 
SOLVED
Go to solution
Manuales
Super Advisor

2>&1 (what is the meaning?) <:0 /

Hi, could you tell me what is the meaning of next sintax at the end of a line in a cron?

¿2>&1? --> <:0 / (no idea)

i know that number 2 is to rredirect errors but i don't know for what is used &1

Thanks, Manuales.



3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: 2>&1 (what is the meaning?) <:0 /

2>&1 is used to redirect the output of standard error (file descriptor 2) to standard out (file descriptor 1) so that both output streams go to the same place.

You will sometimes see it like:

command > /dev/null 2>&1

This tells you:

> /dev/null --- This redirects standard out to /dev/null

2>&! -- Redirect standard error to standard out.

The cumulative effect is that std. error is redirected to std. out, which is redirected to /dev/null, so effectively both std. error and std. out go to /dev/null thus throwing away any output that the command generates.

You can also redirect all output to a regular file by:

command > /var/tmp/somefilename 2>&1

This causes std. error and std. out output to be sent to /var/tmp/somefilename for later review.

I hope this clears it up for you.
Manuales
Super Advisor

Re: 2>&1 (what is the meaning?) <:0 /

Thanks !!!

<:D Manuales
Laurent Menase
Honored Contributor

Re: 2>&1 (what is the meaning?) <:0 /

just a remark, the order of the redirection is important if you reverse the order:

command 2>&1 >/dev/null

the stderr of command will be out on the standard output and stdout to /dev/null