Linux - Redirection of Standard output/input
来源:互联网 发布:2016年全国经济数据 编辑:程序博客网 时间:2024/06/05 07:31
转自 http://doc.dev.md/lsst/ch02sec15.html
There are three main redirection symbols >,>>,<
> if file already exist, it will be overwritten else new file is created.
After input, press CTRL + D to save file.
>> if file exist , it will be opened and new information/data will be written to END of file, without losing previous information/data, And if file is not exist, then new file is created.
< To take input to Linux-command from file instead of key-board.
In Linux (And in C programming Language) your keyboard, screen etc are all treated as files. Following are name of such files
Standard FileFile Descriptors numberUseExamplestdin0as Standard input Keyboardstdout1as Standard outputScreenstderr2as Standard error ScreenBy default in Linux every program has three files associated with it, (when we start our program these three files are automatically opened by your shell). The use of first two files (i.e. stdin and stdout) , are already seen by us. The last file stderr (numbered as 2) is used by our program to print error on screen. You can redirect the output from a file descriptor directly to file with following syntax
Syntax:
file-descriptor-number>filename
Note:
command or script >file_name等同于command or script 1>file_name,即将stdout的内容redirect到file_name中。如果要将stderr的内容redirect到file中,则需要明确写出为:
command or script 2>file_name
如果直接使用File Descriptors number来redirect,则语法为:from>&destination
如: 1>&2
在script中,echo语句都将输出到stdout中,如果要将其转为stderr输出,则需要在echo语句后面加1>&2,如 echo "Error : Number are not supplied" 1>&2
如此一来,可以将script的输出信息同时分别redirect到不同的文件中,如 script >info_file 2>error_file
(等同于 script 1>info_file 2>error_file)
>和<可以同时使用,如 command <input_file >output_file
并且没有顺序限制,也可以这种使用 command >output_file <input_file
0 0
- Linux - Redirection of Standard output/input
- Standard Input and Output Redirection
- Redirection on input/output.
- Redirecting standard input and output
- Standard input, output, and error streams
- linux input/output error
- Piping and Redirection,output,Reading from STDIN in script(Linux)
- Input and output of iostream.
- Redirecting Standard Input/Output using the Process Class
- Linux出现Input/output error
- xargs - a reconstruction tool of standard input
- I/O of python (INPUT / OUTPUT)
- Checking standard output of PBS jobs in real time
- Linux服务器Input/output error错误
- tq2440移植Linux:input/output error
- LINUX mount.nfs: Input/output error
- input/output
- Nuance deadlock on console output redirection.
- 安卓定时获得wifi强度编程
- Linux - Wild cards
- 介绍一个提高Android ListView或GridView的Smoothie库
- Ubuntu 12.04上Android MTP连接
- Linux - 各种快捷方式代表的含义
- Linux - Redirection of Standard output/input
- Request.urlReffer Request获取url各种信息的方法
- 结构体对齐
- Linux - tr utility (translateing range of characters)
- Java数据库编程---Blob
- NSNumberFormatter的使用
- 倾尽天下
- linux系统 进程管理一点总结【001】
- Linux - Linux Command Related with Process