Why does the cat command only read from the first file descriptor?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












From the console, I've created 2 empty files, and I tried to read them simultaneously.



$ echo -n '' | tee f1 > f2
$ cat f1 f2
$ cat <(tail -f f1) <(tail -f ./f2)


On the other console I've run my tests.



$ echo 'tee test' | tee -a f1 >> f2
$ echo 'f1 test' >> f1
$ echo 'f2 test' >> f2
$ cat f1 f2
tee test
f1 test
tee test
f2 test


However, cat on the first console only read outputs from the first fd.



$ cat <(tail -F ./f1) <(tail -F ./f2)
tee test
f1 test


Why? How do I then read simultaneously from two or more file descriptors?







share|improve this question


























    up vote
    1
    down vote

    favorite












    From the console, I've created 2 empty files, and I tried to read them simultaneously.



    $ echo -n '' | tee f1 > f2
    $ cat f1 f2
    $ cat <(tail -f f1) <(tail -f ./f2)


    On the other console I've run my tests.



    $ echo 'tee test' | tee -a f1 >> f2
    $ echo 'f1 test' >> f1
    $ echo 'f2 test' >> f2
    $ cat f1 f2
    tee test
    f1 test
    tee test
    f2 test


    However, cat on the first console only read outputs from the first fd.



    $ cat <(tail -F ./f1) <(tail -F ./f2)
    tee test
    f1 test


    Why? How do I then read simultaneously from two or more file descriptors?







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      From the console, I've created 2 empty files, and I tried to read them simultaneously.



      $ echo -n '' | tee f1 > f2
      $ cat f1 f2
      $ cat <(tail -f f1) <(tail -f ./f2)


      On the other console I've run my tests.



      $ echo 'tee test' | tee -a f1 >> f2
      $ echo 'f1 test' >> f1
      $ echo 'f2 test' >> f2
      $ cat f1 f2
      tee test
      f1 test
      tee test
      f2 test


      However, cat on the first console only read outputs from the first fd.



      $ cat <(tail -F ./f1) <(tail -F ./f2)
      tee test
      f1 test


      Why? How do I then read simultaneously from two or more file descriptors?







      share|improve this question














      From the console, I've created 2 empty files, and I tried to read them simultaneously.



      $ echo -n '' | tee f1 > f2
      $ cat f1 f2
      $ cat <(tail -f f1) <(tail -f ./f2)


      On the other console I've run my tests.



      $ echo 'tee test' | tee -a f1 >> f2
      $ echo 'f1 test' >> f1
      $ echo 'f2 test' >> f2
      $ cat f1 f2
      tee test
      f1 test
      tee test
      f2 test


      However, cat on the first console only read outputs from the first fd.



      $ cat <(tail -F ./f1) <(tail -F ./f2)
      tee test
      f1 test


      Why? How do I then read simultaneously from two or more file descriptors?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 20 '17 at 18:26









      Jeff Schaller

      32.1k849109




      32.1k849109










      asked Oct 20 '17 at 14:32









      NarūnasK

      8021618




      8021618




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          cat processes its arguments sequentially; tail -f f1 continues running, so cat keeps waiting for input on <(tail -f f1), and doesn’t move on to processing <(tail -f f2).



          You’ll see the output from tail -f f2 if you kill the first tail.



          A better tool to track multiple files simultaneously is tail itself (at least, GNU tail):



          tail -f f1 f2


          If you don’t want to see file headers, use -q:



          tail -qf f1 f2





          share|improve this answer




















          • That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
            – dhag
            Oct 20 '17 at 14:41

















          up vote
          2
          down vote













          cat a b doesn't read simultaneously from a and b; it opens a,
          reads it from start to finish, closes a, and then goes on to do the
          same with the next file it was given as an argument.



          In the case where the arguments are pseudo-files that do tail -f and
          thus do not have an "end", cat would only ever read from the first file.



          If for some reason all you need is to open many files at once, paste
          could be a way:



          $ echo f1 >f1; echo f2 >f2
          $ cat <(tail -F f1) <(tail -F f2)
          f1
          ^C

          $ paste <(tail -F f1) <(tail -F f2)
          f1 f2
          ^C





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399359%2fwhy-does-the-cat-command-only-read-from-the-first-file-descriptor%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            6
            down vote



            accepted










            cat processes its arguments sequentially; tail -f f1 continues running, so cat keeps waiting for input on <(tail -f f1), and doesn’t move on to processing <(tail -f f2).



            You’ll see the output from tail -f f2 if you kill the first tail.



            A better tool to track multiple files simultaneously is tail itself (at least, GNU tail):



            tail -f f1 f2


            If you don’t want to see file headers, use -q:



            tail -qf f1 f2





            share|improve this answer




















            • That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
              – dhag
              Oct 20 '17 at 14:41














            up vote
            6
            down vote



            accepted










            cat processes its arguments sequentially; tail -f f1 continues running, so cat keeps waiting for input on <(tail -f f1), and doesn’t move on to processing <(tail -f f2).



            You’ll see the output from tail -f f2 if you kill the first tail.



            A better tool to track multiple files simultaneously is tail itself (at least, GNU tail):



            tail -f f1 f2


            If you don’t want to see file headers, use -q:



            tail -qf f1 f2





            share|improve this answer




















            • That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
              – dhag
              Oct 20 '17 at 14:41












            up vote
            6
            down vote



            accepted







            up vote
            6
            down vote



            accepted






            cat processes its arguments sequentially; tail -f f1 continues running, so cat keeps waiting for input on <(tail -f f1), and doesn’t move on to processing <(tail -f f2).



            You’ll see the output from tail -f f2 if you kill the first tail.



            A better tool to track multiple files simultaneously is tail itself (at least, GNU tail):



            tail -f f1 f2


            If you don’t want to see file headers, use -q:



            tail -qf f1 f2





            share|improve this answer












            cat processes its arguments sequentially; tail -f f1 continues running, so cat keeps waiting for input on <(tail -f f1), and doesn’t move on to processing <(tail -f f2).



            You’ll see the output from tail -f f2 if you kill the first tail.



            A better tool to track multiple files simultaneously is tail itself (at least, GNU tail):



            tail -f f1 f2


            If you don’t want to see file headers, use -q:



            tail -qf f1 f2






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 20 '17 at 14:40









            Stephen Kitt

            144k22313378




            144k22313378











            • That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
              – dhag
              Oct 20 '17 at 14:41
















            • That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
              – dhag
              Oct 20 '17 at 14:41















            That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
            – dhag
            Oct 20 '17 at 14:41




            That might be a more sensible suggestion than mine; I had not understood what the OP meant to achieve.
            – dhag
            Oct 20 '17 at 14:41












            up vote
            2
            down vote













            cat a b doesn't read simultaneously from a and b; it opens a,
            reads it from start to finish, closes a, and then goes on to do the
            same with the next file it was given as an argument.



            In the case where the arguments are pseudo-files that do tail -f and
            thus do not have an "end", cat would only ever read from the first file.



            If for some reason all you need is to open many files at once, paste
            could be a way:



            $ echo f1 >f1; echo f2 >f2
            $ cat <(tail -F f1) <(tail -F f2)
            f1
            ^C

            $ paste <(tail -F f1) <(tail -F f2)
            f1 f2
            ^C





            share|improve this answer
























              up vote
              2
              down vote













              cat a b doesn't read simultaneously from a and b; it opens a,
              reads it from start to finish, closes a, and then goes on to do the
              same with the next file it was given as an argument.



              In the case where the arguments are pseudo-files that do tail -f and
              thus do not have an "end", cat would only ever read from the first file.



              If for some reason all you need is to open many files at once, paste
              could be a way:



              $ echo f1 >f1; echo f2 >f2
              $ cat <(tail -F f1) <(tail -F f2)
              f1
              ^C

              $ paste <(tail -F f1) <(tail -F f2)
              f1 f2
              ^C





              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                cat a b doesn't read simultaneously from a and b; it opens a,
                reads it from start to finish, closes a, and then goes on to do the
                same with the next file it was given as an argument.



                In the case where the arguments are pseudo-files that do tail -f and
                thus do not have an "end", cat would only ever read from the first file.



                If for some reason all you need is to open many files at once, paste
                could be a way:



                $ echo f1 >f1; echo f2 >f2
                $ cat <(tail -F f1) <(tail -F f2)
                f1
                ^C

                $ paste <(tail -F f1) <(tail -F f2)
                f1 f2
                ^C





                share|improve this answer












                cat a b doesn't read simultaneously from a and b; it opens a,
                reads it from start to finish, closes a, and then goes on to do the
                same with the next file it was given as an argument.



                In the case where the arguments are pseudo-files that do tail -f and
                thus do not have an "end", cat would only ever read from the first file.



                If for some reason all you need is to open many files at once, paste
                could be a way:



                $ echo f1 >f1; echo f2 >f2
                $ cat <(tail -F f1) <(tail -F f2)
                f1
                ^C

                $ paste <(tail -F f1) <(tail -F f2)
                f1 f2
                ^C






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 20 '17 at 14:40









                dhag

                10.7k32742




                10.7k32742



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399359%2fwhy-does-the-cat-command-only-read-from-the-first-file-descriptor%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay