Redirecting Input and Output with File Descriptors

When you execute the history command, the program’s output is displayed on the screen. The history command writes its output to standard output, and standard output is mapped to your terminal screen by default.

You’ve already used the > and >> symbols to redirect a program’s output to a file. For example, you can save the contents of your shell history to a file:

 $ ​​history​​ ​​>​​ ​​commands.txt

You also know that the >> symbol appends text to an existing file. For example, you can append today’s date to the file you just created:

 $ ​​date​​ ​​>>​​ ​​commands.txt

Here’s how this concept works. The > and >> symbols redirect content to file descriptors, an abstract way for the OS to ...

Get Small, Sharp Software Tools 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.