Skip to Content
Learning the Unix Operating System, 5th Edition
book

Learning the Unix Operating System, 5th Edition

by John Strang, Grace Todino, Jerry Peek
October 2001
Beginner
174 pages
4h 33m
English
O'Reilly Media, Inc.
Content preview from Learning the Unix Operating System, 5th Edition

Chapter 5. Redirecting I/O

Many Unix programs read input (such as a file) and write output. In this chapter, we discuss Unix programs that handle their input and output in a standard way. This lets them work with each other.

This chapter generally doesn’t apply to full-screen programs, such as the Pico editor, that take control of your whole terminal window. (The pager programs, less, more, and pg, do work together in this way.) It also doesn’t apply to graphical programs, such as StarOffice or Netscape, that open their own windows on your screen.

Standard Input and Standard Output

What happens if you don’t give a filename argument on a command line? Most programs will take their input from your keyboard instead (after you press the first RETURN to start the program running, that is). Your terminal keyboard is the program’s standard input.

As a program runs, the results are usually displayed on your terminal screen. The terminal screen is the program’s standard output.

So, by default, each of these programs takes its input from the standard input and sends the results to the standard output.

These two default cases of input/output (I/O) can be varied. This is called I/O redirection.

If a program doesn’t normally read from files, but reads from its standard input, you can give a filename by using the < (less-than symbol) operator. For example, the mail program (see Section 6.5.2 in Chapter 6) normally reads the message to send from your keyboard. Here’s how to use the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Learning the UNIX Operating System, Fourth Edition

Learning the UNIX Operating System, Fourth Edition

Grace Todino, John Strang, Jerry Peek
Hands-On System Programming with Linux

Hands-On System Programming with Linux

Kaiwan N. Billimoria, Tigran Aivazian
UNIX and Linux System Administration Handbook, 5th Edition

UNIX and Linux System Administration Handbook, 5th Edition

Trent R. Hein, Evi Nemeth, Garth Snyder, Ben Whaley, Dan Mackin

Publisher Resources

ISBN: 0596002610Errata Page