tee 是一款 Linux 系统工具,它可以将输出内容同时重定向到文件和屏幕。
默认情况
默认在 Linux 执行一个程序后,会直接将输出内容打印到屏幕上。
[root@nas tmp]# ls
seahub_cache systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-ntpd.service-Lg3bPY
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-mariadb.service-1nbZ99 systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-php-fpm.service-NtYNDq
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-nginx.service-38MFbH thunder
重定向到文件
如果要重定向到文件,则屏幕上不会显示。如图输入下面命令会将输出的内容重定向到 file 文件。
[root@nas tmp]# ls >> file
[root@nas tmp]#
重定向到文件和屏幕
使用 tee 可以将输出内容同时重定向到文件和屏幕。
[root@nas tmp]# ls | tee file
file
seahub_cache
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-mariadb.service-1nbZ99
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-nginx.service-38MFbH
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-ntpd.service-Lg3bPY
systemd-private-b721acabf10b4ea3bf49f3b52c54edfe-php-fpm.service-NtYNDq
thunder
[root@nas tmp]#
追加输出到文件
为 tee 增加 -a 参数可以以追加而不是覆盖模式写到文件。
[root@nas tmp]# ls | tee -a file
鼓励下啦