Ubuntu/Linux/QNX · 2012/10/25

将cmd命令结果输出到文件

通过telnet连接设备的时候,有时候有些命令的结果特别长,刷了好几个屏幕,这时候就需要打印到文件啦。

感谢 http://linux.101hacks.com/unix/tee-command-examples/ 提供了办法:

Example 1: Write output to stdout, and also to a file

The following command displays output only on the screen (stdout).

$ ls

The following command writes the output only to the file and not to the screen.  打印到文件,这个文件默认存储在telnet对象的当前工作空间

$ ls > file

The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file. 同时显示在命令窗口并打印到文件

$ ls | tee file