Tee命令用來(lái)同時(shí)存儲(chǔ)和展示其他命令的輸出
1. 輸出到Console同時(shí)寫(xiě)入文件
使用ls查看文件夾下內(nèi)容:
$ ls
account cache crash
同時(shí)需要保存到文件filelist.txt(否者需要ls > filelist.txt
):
$ ls | tee filelist.txt
account
cache
crash
filelist.txt
查看filelist.txt中,會(huì)看到包含了上一條命令的輸出:
2. 輸出使用在多條命令中:
查看并備份當(dāng)前crontab后,更新crontab內(nèi)容(old->new)
$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab
3. 使用append(默認(rèn)覆蓋)
$ ls | tee –a file
4, 多文件寫(xiě)
$ ls | tee file1 file2 file3