Standard File Descriptors

 

Standard File Descriptors

Every running program under Unix starts with three files already opened

Table 1-1. Standard Files Provided by Unix

Descriptive NameFile NumberDescription
Standard In0Input from the keyboard
Standard Out1Output to the console
Standard Error2Error output to the console

So by default, all input will come from the keyboard and all output (both normal and error output) will go to the screen.

Figure 1-2. Default Unix Files

The Shell

The shell is your gateway to interacting with the operating system. It has only one major task -- to allow you to execute programs (you will begin to understand how the shell actually does this when we talk about some of the internals of the operating system later).

But modern shells do much more than allow you to simply execute a program. They have powerful abilities to redirect files, allow you to execute multiple programs simultaneously and script complete programs.

Redirection

Often we do not want the standard files mentioned above to point to their default places. For example, you may wish to capture all the output of a program into a file on disk, or, alternatively have it read its commands from a file you prepared earlier. Another useful task might like to pass the output of one program to the input of another. It should come as no surprise you shell allows you to do all of this (and more!)

Table 1-2. Standard Shell Redirection Facilities

NameCommandDescriptionExample
Redirect to a file> filenameTake all output from standard out and place it into filename. Note using >> will append to the file, rather than overwrite it.ls > filename
Read from a file< filenameCopy all data from the file to the standard input of the programecho < filename
Pipeprogram1 | program2Take everything from standard out of program1 and pass it to standard input of program2ls | more

 

the original link:http://bottomupcs.sourceforge.net/csbu/x153.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值