問題,一些指令輸出無法定向到檔案
[email protected]:~# time > a.txt
real 0m0.000s
user 0m0.000s
sys 0m0.000s
執行後沒有将輸出列印到a.txt檔案 time是shell關鍵字,将time 後面一整行作為指令執行了,
[email protected]:~# time ls > a.txt
real 0m0.002s
user 0m0.000s
sys 0m0.000s
将ls指令輸出定向到a.txt了,time的輸出依然列印出來了
[email protected]:~# { time ls >b.txt; } 2>a.txt
[email protected]:~# cat a.txt
real 0m0.002s
user 0m0.000s
sys 0m0.000s
發現time執行的輸出定向到a.txt了,ls的輸出定向到b.txt了 大括号代表了另起了一個shell,應該比較占資源
[email protected]:~# (time ls >b.txt) 2>a.txt
[email protected]:~# cat a.txt
real 0m0.002s
user 0m0.000s
sys 0m0.000s
用括号将指令分隔,同樣定向了指令的輸出,我們的shell經常會遇到一些指令執行了無法列印輸出到指定的檔案可以考慮這麼做