Linux command: echo "" | sudo tee /var/log/messages
echo "" | sudo tee /var/log/messages
命令: echo
功能: 在显示器上显示一段文字,一般起到一个提示的作用.
命令: tee
功能:
读取标准输入的数据,并将其内容输出成文件.
(补充: tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件.我们可利用tee把管道导入的数据存成文件,甚至一次保存数份文件.)
格式: tee
只输出到标准输出.
格式: tee file
输出到标准输出的同时,保存到文件file中.如果文件不存在,则创建;如果已经存在,则覆盖.
格式: tee -a file
输出到标准输出的同时,追加到文件file中.如果文件不存在,则创建;如果已经存在,就在末尾追加内容,而不是覆盖.
举例:
[root@localhost bin]# cat /var/log/messages
Mar 15 03:28:01 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1953" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Mar 15 03:28:02 localhost rhsmd: In order for Subscription Manager to provide your system with updates, your system must be registered with the Customer Portal. Please enter your Red Hat login to ensure your system is up-to-date.
Mar 15 19:09:14 localhost kernel: psmouse.c: Wheel Mouse at isa0060/serio1/input0 lost synchronization, throwing 1 bytes away.
Mar 15 19:09:15 localhost kernel: psmouse.c: resync failed, issuing reconnect request
Mar 16 03:03:06 localhost dhclient[2039]: DHCPREQUEST on eth0 to 10.237.80.131 port 67 (xid=0x3a80f229)
Mar 16 03:03:06 localhost dhclient[2039]: DHCPACK from 10.237.80.131 (xid=0x3a80f229)
Mar 16 03:03:06 localhost dhclient[2039]: bound to 10.237.88.109 -- renewal in 340498 seconds.
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> (eth0): DHCPv4 state changed renew -> renew
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> address 10.237.88.109
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> prefix 23 (255.255.254.0)
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> gateway 10.237.88.1
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> nameserver ‘10.237.80.131‘
Mar 16 03:03:06 localhost NetworkManager[2018]: <info> domain name ‘acschina.com‘
Mar 16 03:41:18 localhost rhsmd: In order for Subscription Manager to provide your system with updates, your system must be registered with the Customer Portal. Please enter your Red Hat login to ensure your system is up-to-date.
Mar 17 03:13:43 localhost rhsmd: In order for Subscription Manager to provide your system with updates, your system must be registered with the Customer Portal. Please enter your Red Hat login to ensure your system is up-to-date.
Mar 18 03:37:07 localhost rhsmd: In order for Subscription Manager to provide your system with updates, your system must be registered with the Customer Portal. Please enter your Red Hat login to ensure your system is up-to-date.
[root@localhost bin]# echo "" | tee /var/log/messages
[root@localhost bin]# cat /var/log/messages
[root@localhost bin]#
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。