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?


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
  • 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

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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.