简体   繁体   English

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

[英]BASH - how to redirect output 1 and 2 to file and screen?

how to redirect output 1 and 2 to file and screen? 如何将输出1和2重定向到文件和屏幕?

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

all output to file and screen 所有输出到文件和屏幕

thank you 谢谢

The tee command directs output to both a file and the tty. tee命令将输出定向到文件和tty。

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

writes the same "hi there" to both outputfile and to the tty. 将相同的“ hi there”写入到outputfile和tty中。 This redirects 1 and 2. 这将重定向1和2。

From your description try script: 从您的描述尝试脚本:

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

I have 1000 commands 我有1000个命令

example

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

I need to send the result to the screen and also save into the file. 我需要将结果发送到屏幕上并保存到文件中。

Nobody knows what will run the command. 没有人知道什么将运行命令。

Thank you 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM