-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Feb 08, 2016 at 04:27:47PM -0700, Bob Holtzman wrote:

[...]

> As root journalctl produces a long list, tail journalctl produces 
> 
> "tail: cannot open ‘journalctl’ for reading: No such file or directory".
> 
> Now I'm really confused. Any explanation?

Others have already answered the practical side of this, so I want to
emphasize the "component" side (yeah, journalctl has a built-in pager,
yadda, but learning to compose tools is what gives you more independence,
so...)

Tail is a so-called filter. It takes an input stream (a stream of
characters [1] and produces an output -- the last 10 lines of this
input.

The input is the file you give by name in the commad line (as in
"tail /var/log/messages" -- or just the standard input (as in
"tail < /var/log/messages".

The two examples above are deceptively similar, but work quite
differently: in the first case, it's the tail program which "sees"
the file name, goes and opens it, and does its thing.

In the second case (note the shell redirection symbol '<') it's
the *shell* which opens the file and feeds its content to tail
via its standard input. In the second case tail doesn't even
know the file name!

When you have no file, but just a program which outputs a stream
to its standard output, you use this second mode of operation
of tail. You use the pipe symbol '|' to tell the shell to connect
the standard output of one program to the other.

This is the case with journalctl (but also, for example with dmesg,
as in 'dmesg | tail'.

There are other filter programs, like e.g. grep, which looks for
a pattern in its input and outputs just the lines matching this
pattern (it can do lots more, but for this example, let's leave
it at that): "dmesg | grep drm" will show you all lines output
by dmesg which contain the pattern "drm".

If you want to have just the last 10 of those, you can just
stick the filters together:

  dmesg | grep drm | tail

Exercise: what would

  dmesg | tail | grep drm

do? Is it the same as the one above? Why? Why not?

regards

[1] I'll gloss over the complications of character vs. byte here

- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAla5l90ACgkQBcgs9XrR2kamzACcD5YmnMzvGamcR+3S7U1QheAQ
2KUAnRS2QkHc9s5XbxooZ0NY6PCydr4q
=Q+uY
-----END PGP SIGNATURE-----

Reply via email to