tee 是一款 Linux 系統工具,它可以将輸出内容同時重定向到檔案和螢幕。
預設情況
預設在 Linux 執行一個程式後,會直接将輸出内容列印到螢幕上。
[[email protected] 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 檔案。
[[email protected] tmp]# ls >> file
[[email protected] tmp]#
重定向到檔案和螢幕
使用 tee 可以将輸出内容同時重定向到檔案和螢幕。
[[email protected] 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
[[email protected] tmp]#
追加輸出到檔案
為 tee 增加 -a 參數可以以追加而不是覆寫模式寫到檔案。
[[email protected] tmp]# ls | tee -a file