Results 1 to 3 of 3

Thread: what does 2>&1 mean?

  1. #1

    what does 2>&1 mean?

    Please explain in words what this means:


    The entire line is
    /usr/sbin/crond l1 >>/var/adm/cron 2>&1

    I read this as "redirect the standard error output to the background process number one". Say What?! <g>

    (I do understand the prior part of that line.)


  2. #2

    Re: what does 2>&1 mean?

    Well bash scripting isn't one of my strong points, going to have to do something about that ;D, but I'll give it a shot.

    /usr/sbin/crond l1 >>/var/adm/cron 2>&1

    Might as well start from the beginning:


    This runs the the executable /usr/bin/crond


    If /usr/bin/crond exits with a status of 1. A 1 exit status means error

    >>/var/adm/cron 2>&1

    Append, >> means append, to the file /var/adm/cron the output of standard output, 1 means standard output, and the output of standard error, 2 means standard error.

    So all together we have, run /usr/sbin/crond and if it exits with an error append the standard output and standard error of /usr/sbin/crond to the file /var/adm/cron.

    Do you follow or did I confuse you more?

    Jim H

  3. #3

    Red face

    Yes indeed from all who wrote. I use it extensively when executing sql statements on the command line of Linux. Here is an easy example. When using PostgreSQL:

    #psql mydatabase -f mysql.sql > mysql.rpt 2>&1


    psql is the postgreSQL command to enter any given database

    mydatabase is a database that was created to execute sql statements

    -f stands for file obviously

    mysql.sql contains a stream of sql statements which will execute against mydatabase database

    mysql.rpt will contain the result of whatever mysql.sql will bring as output


    2>&1 is basically as JimH stated here above.

    Yes Linux is an Egyptian language in my book, but I do enjoy using it even more than just Unix. Having been in this business since ENIACS LOLs....I love it all together...

    Hope this helps the reader...I have lots of other Egyptian type of commands and so forth...

    Happy New Year to all of you.
    Last edited by californiasailor; 01-12-2013 at 02:32 PM. Reason: typos


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts