py守护进程

http://www.4pang.com/2010/09/21/%E7%94%A8python%E7%BC%96%E5%86%99linux%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B.html

good good article linux shell简介,especially 第三章输入输出的重定向

http://www.linuxsir.org/main/?q=node/135

shell重定向的再学习

 (2005-06-09 16:39:07)

 分类: shell脚本

今天遇到一个古怪的问题:

运行
sudo -u www php a.php > xxxxx
sudo -u www php a.php 2> xxxxx
正确执行;

运行
sudo -u www php a.php 2>&1 >xxxxx
把输出结果保存到xxxx里面了,但并没有把错误也保存起来;

这是我一直没有注意到的地方,也就是说命令写得有问题;

google吧,ft,访问不了;
用yahoo找找吧(刚用几天,还不习惯);

//////////////////////////////////////////////////////////////////////

先看看shell manpage的解释:

REDIRECTION
.................

Note that the order of redirections is significant. For example, the command
ls > dirlist 2>&1 
directs both standard output and standard error to the file dirlist, while the command
ls 2>&1 > dirlist 
directs only the standard output to file dirlist, because the standard error was duplicated as standard output before the standard output was redirected to dirlist. 
原来,位置不一样,结果还不一样。汗啊
按照我的理解,第二条命令也应该是对的吧:)
把2重定向到1,再把1重定向到文件,所以2也重定向到文件了;
想不到会这么“奇怪”,也许,shell就是一个怪东西,只要适应了就好了;

Redirecting Output

Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n, or the standard output (file descriptor 1) if n is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size.

The general format for redirecting output is:

[n]>word 

If the redirection operator is >, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is >|, or the redirection operator is > and the noclobber option to the set builtin command is not enabled, the redirection is attempted even if the file named by word exists. 

看看这个,还可以这样写呢 !不知道是不是只有bash支持。其他shell支持吗?
Redirecting Standard Output and Standard Error

Bash allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of word with this construct.

There are two formats for redirecting standard output and standard error:
&>word 
and
>&word 
Of the two forms, the first is preferred. This is semantically equivalent to
>word 2>&1 

以后写重定向,得按照这种格式写了:

>word 2>&1
标准输入 
标准输入是文件描述符0.它是命令的输入,缺省是键盘,也可以是文件或其它的命令输出 

标准输出 
标准输出是文件描述符1.它是命令的输出,缺省是屏幕,也可以是文件 

标准错误 
标准错误是文件件描述符2。它是命令错误码率的输出,缺省是屏幕,同样也可以是文件. 


重定向操作符 描述 
>        将命令输出写入到文件或设备(如打印机),而不是命令提示符窗口或句柄。 

<        从文件而不是从键盘或句柄读入命令输入。 

>>       将命令输出添加到文件末尾而不删除文件中已有的信息。 

>&       将一个句柄的输出写入到另一个句柄的输入中。 

<&       从一个句柄读取输入并将其写入到另一个句柄输出中。 

|        从一个命令中读取输出并将其写入另一个命令的输入中。也称作管道。 

常用文件重定向命令 
Shell代码 
  1. command > filename              把标准输出重定向到一个新文件中  
  2. command >> filename             把标准输出重定向到一个文件中(追加)  
  3. command 1 > fielname            把标准输出重定向到一个文件中  
  4. command > filename 2>&1         把标准输出和标准错误一起重定向到一个文件中  
  5. command 2 > filename            把标准错误重定向到一个文件中  
  6. command 2 >> filename           把标准输出重定向到一个文件中(追加)  
  7. command >> filename 2>&1        把标准输出和标准错误一起重定向到一个文件中(追加)  
  8. command < filename >filename2   把command命令以filename文件作为标准输入,以filename文件作为标准输出  
  9. command < filename              把command命令以filename文件作为标准输入  
  10. command << delimiter            把从标准输入中读入,直至遇到d e l i m i t e r分界符  
  11. command <&m                     把把文件描述符m作为标准输入  
  12. command >&m                     把把标准输出重定向到文件描述符m中  

原文地址:https://www.cnblogs.com/lexus/p/1833330.html