|
与设备无关的输入输出
对于UNIX程序,设备(例如打印机或终端)和磁盘文件都是作为文件出现的。当你给UNIX操作系统一个命令时,可以指挥操作系统把输出送到任何设备或文件上去,这种变更操作称为输出重定向。
用同样的方法,对在正常情况下终端的程序输入也可以重定向,使输入来自磁盘文件。在UNIX操作系统下,输入输出与设备无关,它们可以重定向到或来自任何一种适当的设备。
例如,cat实用程序通常用来在终端屏幕上显示文件的内容。输入cat命令时,可以将文件的内容输出到一个磁盘文件上而不是到终端上。
Device-Independent Input and Output
Devices(such as a printer or terminal)and disk files all appear as files to UNIX programs.When you give the UNIX operating system a command,you can instruct it to send the output to any one of several devices or files.This diversion is called output redirection.
In a similar manner,a program’s input that normally comes from a terminal can be redirected so that it comes from a disk file instead.Under the UNIX operating system,input and output are device -independent;they can be redirected to or from any appropriate device.
As an example,the cat utility normally displays the contents of a file on the terminal screen.When you enter a cat command,you can cause its output to go to a disk file instead of to the terminal. |
|