如何在输出信息的同时将其保存在文件中? 
 有三种方式 
 此种方式不能输出信息,只能保存在文件中 
 1. 直接将命令的结果用 > 把输出转向 
 [root@www ~]# ls >ls.txt 
 [root@www ~]# cat ls.txt 
 anaconda-ks.cfg 
 cronolog-1.6.2 
 install.log 
 install.log.syslog 
 ls_tee.txt 
 ls.txt 
 typescript
2.利用tee在输出信息的同时保存到文件中 
 tee的含义:read from standard input and write to standard output and files
[root@www ~]# ls | tee ls_tee.txt 
 anaconda-ks.cfg 
 cronolog-1.6.2 
 install.log 
 install.log.syslog 
 ls_tee.txt 
 ls.txt 
 typescript 
 [root@www ~]# cat ls_tee.txt 
 anaconda-ks.cfg 
 cronolog-1.6.2 
 install.log 
 install.log.syslog 
 ls_tee.txt 
 ls.txt 
 typescript
3.多个命令的输出都需要记录,可以用script
[root@www ~]# script 
 Script. started, file is typescript 
 [root@www ~]# ls 
 anaconda-ks.cfg install.log ls_tee.txt typescript 
 cronolog-1.6.2 install.log.syslog ls.txt 
 [root@www ~]# exit 
 exit 
 Script. done, file is typescript 
 [root@www ~]# cat typescript 
 Script. started on Fri 28 Sep 2012 05:27:02 PM CST 
 [root@www ~]# ls 
 anaconda-ks.cfg install.log ls_tee.txt typescript 
 cronolog-1.6.2 install.log.syslog ls.txt 
 [root@www ~]# exit 
 exit
Script. done on Fri 28 Sep 2012 05:27:12 PM CST
在启动script时没有指定文件名,它会自动记录到当前文件夹下一个文件名为typescript的文件中。也可以用-a 参数 指定文件名 
 [root@www ~]# script. -a example.txt
另外还可以录制 
 并播放session的内容 
   我们可以用 script把整个终端会话的所有操作和输出录制下来,然后再用scriptreplay进行播放。 
   如果录制时记录下来了操作时的时间数据,那么播放时和操作时的使用时间完全相同, 
   这个很有用吧,比如:我们可以把安装软件时编译的过程记录下来,然后给别人进行演示 
   看例子: 
   script.−t2>example.time−aexample.txt  Script.started,fileisexample.txt ls 
   说明: -t 2>example.time -t是把时间数据输出到标准错误(standard error) 
   所以我们使用 2>example.time 把数据转向到 example.time这个文件当中 
   如何播放所记录的内容? 
   第一步:安装scriptreplay 
   下载 
   wget linux/utils/util-linux/util-linux-2.12r.tar.bz2”>ftp://ftp.kernel.org/pub/linux/utils/util-linux/util-linux-2.12r.tar.bz2 
   解压 
   tar -jxvf util-linux-2.12r.tar.bz2 
   之后复制文件到系统的命令目录中即可 
   # cp util-linux-2.12r/misc-utils/scriptreplay.pl /usr/bin/scriptreplay 
   # chmod 755 /usr/bin/scriptreplay 
   备注: fedora 10的util-linux-ng-2.14.1-3.2.fc10.i386.rpm 此包中已包含 scriptreplay,已无需另行安装 
   第二步:播放所录制的session内容 
   scriptreplayexample1.timeexample1.txt ls 
   1.gtkrc-2.0 c.tar pass 
   abcd  bash:abcd:commandnotfound
录制及播放没有测试过
                










