Linux 管理員 - tee 命令



tee 這是一個簡單的命令,允許管理員在同時檢視檔案的情況下撰寫命令輸出。此簡單命令可節省時間,避免先將 stdout 寫入檔案,再檢視檔案內容。

下面是與 tee 搭配使用的一些常見開關。

命令 操作
-a 追加到檔案,而不是覆蓋檔案
-i 忽略中斷(主要用於高階指令碼用途)

如果沒有 tee 同時檢視和編寫 /etc 中以“a”開頭的檔案和目錄。

[root@centosLocal Documents]# ls -d /etc/a*
/etc/abrt     /etc/aliases.db    /etc/anacrontab   /etc/at-spi2  /etc/autofs.conf
/etc/auto.master.d  /etc/auto.smb  /etc/adjtime  /etc/alsa      /etc/asound.conf
/etc/audisp         /etc/autofs_ldap_auth.conf  /etc/auto.misc  /etc/avahi
/etc/aliases  /etc/alternatives  /etc/at.deny   /etc/audit   /etc/auto.master
/etc/auto.net
[root@centosLocal Documents]# ls -d /etc/a* > ./etc_report_a.txt
[root@centosLocal Documents]# cat ./etc_report_a.txt
/etc/abrt
/etc/adjtime
/etc/aliases
/etc/aliases.db
/etc/alsa
/etc/alternatives 
/etc/anacrontab 
/etc/asound.conf 
/etc/at.deny 
/etc/at-spi2 
/etc/audisp 
/etc/audit 
/etc/autofs.conf 
/etc/autofs_ldap_auth.conf 
/etc/auto.master 
/etc/auto.master.d 
/etc/auto.misc 
/etc/auto.net 
/etc/auto.smb
/etc/avahi

[root@centosLocal Documents]#

使用 tee 命令,這項小任務的效率會更高。

[root@centosLocal Documents]# ls -d /etc/a* | tee ./etc_report_a.txt 
/etc/abrt 
/etc/adjtime 
/etc/aliases 
/etc/aliases.db 
/etc/alsa 
/etc/alternatives 
/etc/anacrontab 
/etc/asound.conf 
/etc/at.deny 
/etc/at-spi2 
/etc/audisp 
/etc/audit 
/etc/autofs.conf 
/etc/autofs_ldap_auth.conf 
/etc/auto.master 
/etc/auto.master.d 
/etc/auto.misc 
/etc/auto.net 
/etc/auto.smb 
/etc/avahi

[root@centosLocal Documents]#
basic_centos_linux_commands.htm
廣告