Why does the cat command only read from the first file descriptor?
Clash 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?
cat file-descriptors
add a comment |Â
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?
cat file-descriptors
add a comment |Â
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?
cat file-descriptors
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 file-descriptors
edited Oct 20 '17 at 18:26
Jeff Schaller
32.1k849109
32.1k849109
asked Oct 20 '17 at 14:32
Narà «nasK
8021618
8021618
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Oct 20 '17 at 14:40
dhag
10.7k32742
10.7k32742
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password