Redirecting Input and Output

Often commands need to receive input from the keyboard and/or send output to the screen. Whenever data is moved from one program or device to another, it is transferred in a stream. When a program runs, it is connected automatically to an input and an output stream: stdin and stdout. By default, stdin is connected to the keyboard and stdout is connected to the screen. You can redirect stdin and stdout.

The ls command outputs a list of files to stdout, which by default is connected to the screen. You can change the output location using the redirect metacharacter—the greater than sign (>), as follows:

ls > dirlist

The list of files is redirected to a file called dirlist and does not display on the screen. If dirlist ...

Get Spring Into Linux® 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.