BASH - 如何将输出1和2重定向到文件和屏幕?

时间:2013-03-12 02:53:53

标签: linux bash

如何将输出1和2重定向到文件和屏幕?

command 2 1 > /tmp/log and 2 1 screen

所有输出到文件和屏幕

谢谢

2 个答案:

答案 0 :(得分:7)

tee命令将输出定向到文件和tty。

echo 'hi there'  2>&1 | tee outputfile

将相同的“hi there”写入outputfile和tty。 这会重定向1和2。

从您的描述中尝试脚本:

Linux / Unix Command: script

 Command Library
NAME

script - make typescript of terminal session  
SYNOPSIS

script [-a ] [-f ] [-q ] [-t ] [file ]  
DESCRIPTION

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves all dialogue in file If no file name is given, the typescript is saved in the file typescript

答案 1 :(得分:0)

我有1000个命令

例如

apt-get install;
mc;
apt-get update;
echo "foo";
..
..
..
nano /etc/passwd;
ls /tmp/log;
mc;
screen

我需要将结果发送到屏幕并保存到文件中。

没有人知道将运行该命令的内容。

谢谢