Standard Input, Output, and Error

In the previous section, we were redirecting streams known as standard input and standard output. When using a < redirection operator, you are telling the operating system that for just this one command it should ignore the standard input device (which is your keyboard) and instead take its input from a file.

Likewise, when using the > operator you are telling Ubuntu to ignore the standard output device (which is your monitor or, more precisely, the Terminal window) and instead send its output to the supplied file.

You may recall from the section The find Command that sometimes an error message would be displayed when access to a particular folder was not allowed, such as with the following command, in which some of the folders are not permitted to be searched by regular users:

find / -name blackjack

Try this command again now, and you’ll see a whole bunch of error messages scroll past, obscuring the few matches we are interested in.

There’s actually a simple solution for this, which is to strip out the error messages from the useable output. In the previous example we separated the error messages from the output we wanted by piping the output through the more command. But how did it do that?

Streams and Handles

The answer is that Ubuntu uses three different streams for input, output, and error messages, and when you use a > or | for redirection or piping, it affects only standard output, not standard error. This means that when you type this:

find / -name ...

Get Ubuntu: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.