What does 2>/dev/null mean?












171















I would like a brief explanation of the following command line:



grep -i 'abc' content 2>/dev/null 









share|improve this question





























    171















    I would like a brief explanation of the following command line:



    grep -i 'abc' content 2>/dev/null 









    share|improve this question



























      171












      171








      171


      90






      I would like a brief explanation of the following command line:



      grep -i 'abc' content 2>/dev/null 









      share|improve this question
















      I would like a brief explanation of the following command line:



      grep -i 'abc' content 2>/dev/null 






      command-line grep redirect stdout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 6 '18 at 12:54









      Zanna

      50.4k13133241




      50.4k13133241










      asked Sep 26 '13 at 8:21









      NaiveNaive

      1,36481830




      1,36481830






















          3 Answers
          3






          active

          oldest

          votes


















          251














          The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.



          If you don't specify a number then the standard output stream is assumed but you can also redirect errors



          > file redirects stdout to file
          1> file redirects stdout to file
          2> file redirects stderr to file
          &> file redirects stdout and stderr to file



          /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.






          share|improve this answer





















          • 1





            is there a difference between > /dev/null 2>&1 and &> /dev/null

            – Alexander Mills
            Oct 19 '17 at 0:25






          • 7





            In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

            – Warren Hill
            Oct 19 '17 at 2:47



















          18














          In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).



          Some more common use cases for redirection:



          command > /dev/null 2>&1 &


          Run command in the background, discard stdout and stderr



          command >> /path/to/log 2>&1 &


          Run command and append stdout and stderr to a log file.






          share|improve this answer





















          • 2





            Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

            – Craig McQueen
            Nov 30 '15 at 6:43






          • 6





            @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

            – Terry Wang
            Nov 30 '15 at 12:24













          • @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

            – Stack Underflow
            Jan 6 at 23:41





















          6














          /dev/null is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null.



          Further, 2> means that you are redirecting (i.e. >) the stderr (i.e. 2) into the black hole (i.e. /dev/null)



          Your command is:



          grep -i 'abc' content 2>/dev/null 


          Don't try to end with another forward slash like this - 2>/dev/null/ (it's not a directory).






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f350208%2fwhat-does-2-dev-null-mean%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            251














            The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.



            If you don't specify a number then the standard output stream is assumed but you can also redirect errors



            > file redirects stdout to file
            1> file redirects stdout to file
            2> file redirects stderr to file
            &> file redirects stdout and stderr to file



            /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.






            share|improve this answer





















            • 1





              is there a difference between > /dev/null 2>&1 and &> /dev/null

              – Alexander Mills
              Oct 19 '17 at 0:25






            • 7





              In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

              – Warren Hill
              Oct 19 '17 at 2:47
















            251














            The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.



            If you don't specify a number then the standard output stream is assumed but you can also redirect errors



            > file redirects stdout to file
            1> file redirects stdout to file
            2> file redirects stderr to file
            &> file redirects stdout and stderr to file



            /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.






            share|improve this answer





















            • 1





              is there a difference between > /dev/null 2>&1 and &> /dev/null

              – Alexander Mills
              Oct 19 '17 at 0:25






            • 7





              In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

              – Warren Hill
              Oct 19 '17 at 2:47














            251












            251








            251







            The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.



            If you don't specify a number then the standard output stream is assumed but you can also redirect errors



            > file redirects stdout to file
            1> file redirects stdout to file
            2> file redirects stderr to file
            &> file redirects stdout and stderr to file



            /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.






            share|improve this answer















            The > operator redirects the output usually to a file but it can be to a device. You can also use >> to append.



            If you don't specify a number then the standard output stream is assumed but you can also redirect errors



            > file redirects stdout to file
            1> file redirects stdout to file
            2> file redirects stderr to file
            &> file redirects stdout and stderr to file



            /dev/null is the null device it takes any input you want and throws it away. It can be used to suppress any output.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 26 '13 at 13:55

























            answered Sep 26 '13 at 8:38









            Warren HillWarren Hill

            15.4k165376




            15.4k165376








            • 1





              is there a difference between > /dev/null 2>&1 and &> /dev/null

              – Alexander Mills
              Oct 19 '17 at 0:25






            • 7





              In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

              – Warren Hill
              Oct 19 '17 at 2:47














            • 1





              is there a difference between > /dev/null 2>&1 and &> /dev/null

              – Alexander Mills
              Oct 19 '17 at 0:25






            • 7





              In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

              – Warren Hill
              Oct 19 '17 at 2:47








            1




            1





            is there a difference between > /dev/null 2>&1 and &> /dev/null

            – Alexander Mills
            Oct 19 '17 at 0:25





            is there a difference between > /dev/null 2>&1 and &> /dev/null

            – Alexander Mills
            Oct 19 '17 at 0:25




            7




            7





            In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

            – Warren Hill
            Oct 19 '17 at 2:47





            In practice today I don't think there is 2>&1 is an older syntax so &> would not have worked years ago but both are equivalent.

            – Warren Hill
            Oct 19 '17 at 2:47













            18














            In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).



            Some more common use cases for redirection:



            command > /dev/null 2>&1 &


            Run command in the background, discard stdout and stderr



            command >> /path/to/log 2>&1 &


            Run command and append stdout and stderr to a log file.






            share|improve this answer





















            • 2





              Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

              – Craig McQueen
              Nov 30 '15 at 6:43






            • 6





              @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

              – Terry Wang
              Nov 30 '15 at 12:24













            • @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

              – Stack Underflow
              Jan 6 at 23:41


















            18














            In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).



            Some more common use cases for redirection:



            command > /dev/null 2>&1 &


            Run command in the background, discard stdout and stderr



            command >> /path/to/log 2>&1 &


            Run command and append stdout and stderr to a log file.






            share|improve this answer





















            • 2





              Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

              – Craig McQueen
              Nov 30 '15 at 6:43






            • 6





              @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

              – Terry Wang
              Nov 30 '15 at 12:24













            • @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

              – Stack Underflow
              Jan 6 at 23:41
















            18












            18








            18







            In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).



            Some more common use cases for redirection:



            command > /dev/null 2>&1 &


            Run command in the background, discard stdout and stderr



            command >> /path/to/log 2>&1 &


            Run command and append stdout and stderr to a log file.






            share|improve this answer















            In short, it redirects stderr (fd 2) to the black hole (discards the output of the command).



            Some more common use cases for redirection:



            command > /dev/null 2>&1 &


            Run command in the background, discard stdout and stderr



            command >> /path/to/log 2>&1 &


            Run command and append stdout and stderr to a log file.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 6 '18 at 12:57









            Zanna

            50.4k13133241




            50.4k13133241










            answered Sep 26 '13 at 8:32









            Terry WangTerry Wang

            6,31932224




            6,31932224








            • 2





              Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

              – Craig McQueen
              Nov 30 '15 at 6:43






            • 6





              @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

              – Terry Wang
              Nov 30 '15 at 12:24













            • @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

              – Stack Underflow
              Jan 6 at 23:41
















            • 2





              Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

              – Craig McQueen
              Nov 30 '15 at 6:43






            • 6





              @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

              – Terry Wang
              Nov 30 '15 at 12:24













            • @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

              – Stack Underflow
              Jan 6 at 23:41










            2




            2





            Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

            – Craig McQueen
            Nov 30 '15 at 6:43





            Is there a good reason to use > /dev/null 2>&1 instead of &> /dev/null?

            – Craig McQueen
            Nov 30 '15 at 6:43




            6




            6





            @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

            – Terry Wang
            Nov 30 '15 at 12:24







            @CraigMcQueen &> is new in Bash 4, the former is just the traditional way, I am just so used to it (easy to remember).

            – Terry Wang
            Nov 30 '15 at 12:24















            @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

            – Stack Underflow
            Jan 6 at 23:41







            @CraigMcQueen according to a comment on this answer, &> /dev/null may not work in some shells but > /dev/null 2>&1 will work in all POSIX compatible shells.

            – Stack Underflow
            Jan 6 at 23:41













            6














            /dev/null is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null.



            Further, 2> means that you are redirecting (i.e. >) the stderr (i.e. 2) into the black hole (i.e. /dev/null)



            Your command is:



            grep -i 'abc' content 2>/dev/null 


            Don't try to end with another forward slash like this - 2>/dev/null/ (it's not a directory).






            share|improve this answer






























              6














              /dev/null is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null.



              Further, 2> means that you are redirecting (i.e. >) the stderr (i.e. 2) into the black hole (i.e. /dev/null)



              Your command is:



              grep -i 'abc' content 2>/dev/null 


              Don't try to end with another forward slash like this - 2>/dev/null/ (it's not a directory).






              share|improve this answer




























                6












                6








                6







                /dev/null is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null.



                Further, 2> means that you are redirecting (i.e. >) the stderr (i.e. 2) into the black hole (i.e. /dev/null)



                Your command is:



                grep -i 'abc' content 2>/dev/null 


                Don't try to end with another forward slash like this - 2>/dev/null/ (it's not a directory).






                share|improve this answer















                /dev/null is treated as black hole in Linux/Unix, so you can put anything into this but you will not be able to get it back from /dev/null.



                Further, 2> means that you are redirecting (i.e. >) the stderr (i.e. 2) into the black hole (i.e. /dev/null)



                Your command is:



                grep -i 'abc' content 2>/dev/null 


                Don't try to end with another forward slash like this - 2>/dev/null/ (it's not a directory).







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 13 '18 at 6:51









                Zanna

                50.4k13133241




                50.4k13133241










                answered Jun 11 '15 at 10:57









                Indrajeet GourIndrajeet Gour

                16114




                16114






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f350208%2fwhat-does-2-dev-null-mean%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?