CHAPTER 9Data Redirection

Data redirection is when the input or output of a command is redirected using special notation. It is also used for opening and closing files for read and write operations. The forms and syntax of redirection are varied and their meanings are specific. I will cover some of the common uses here, and provide a bit more explanation than system man pages to aid you in avoiding pitfalls.

Avoiding Confusion

Data redirection is a common point of confusion among users. Problems with its usage arise most often when a user wants to set up a cron job that sends all its output to /dev/null, such as in the following crontab entry:

10 5 * * * /run/some/script > /dev/null 2>&1

In this example, all of the output will be sent to /dev/null ...

Get Expert Shell Scripting 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.