2> /dev/null 』;
[dywang@dywHome ~]$ cat /etc/crontab /etc/dywang # /etc/crontab 存在,螢幕出現以下 standard output SHELL=/bin/bash MAILTO=root HOME=/ # run-parts 01 * * * * root nice -n 19 run-parts --report /etc/cron.hourly 02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily 22 4 * * 0 root nice -n 19 run-parts --report /etc/cron.weekly 42 4 1 * * root nice -n 19 run-parts --report /etc/cron.monthly # /etc/dywang 不存在,螢幕出現以下 standard error cat: /etc/dywang: No such file or directory
< 或 <<;
> 或 >>;
2> 或 2>>;
>, 1> |
標準輸出至檔案,該檔案被覆蓋或建立。 | ||
>>, 1>> |
標準輸出至檔案,該檔案被建立或累加。 | ||
| command | 2> |
裝置或檔案 | 錯誤輸出至檔案,該檔案被覆蓋或建立。 |
2>> |
錯誤輸出至檔案,該檔案被建立或累加。 | ||
< |
輸入 | ||
<< |
結束的輸入字元 |
[root@linux ~]# ls -l / > ~/rootfile # 將 ls -l / 要列出到螢幕上的資料『重新導向』到 ~/rootfile 檔案。
~/rootfile )若不存在,系統會自動建立;
> 輸出到一個既存檔案中,該檔案會被覆蓋。
> 與 >>
# 將目前目錄下的檔案資訊儲存到 list.txt [root@linux ~]# ls -al > list.txt # 將根目錄下的資料累加到 list.txt [root@linux ~]# ls -al / >> list.txt
2>
[csie@linux ~]$ find /home -name testing find: /home/test1: Permission denied %*<== Starndard error*) find: /home/root: Permission denied %*<== Starndard error*) find: /home/masda: Permission denied %*<== Starndard error*) /home/csie/testing %*<== Starndard output*) [csie@linux ~]$ find /home -name testing > list_right 2> list_error [csie@linux ~]$ find /home -name testing > list_right 2> /dev/null
2>&1:標準輸出與標準錯誤輸出同時寫入同一個檔案
[csie@linux ~]$ find /home -name testing > list 2> list %*<==錯誤寫法*) ## 習題:請問上面命令的執行結果為何? [csie@linux ~]$ find /home -name testing > list 2>&1 %*<==正確寫法*)
[root@linux ~]# cat > catfile testing cat file test %*<== 按下 [ctrl]+d 結束輸入來離開。*) [root@linux ~]# cat > catfile <<eof > This is a test testing > OK now stop > eof %*<==輸入 eof 時,該次輸入就結束輸了。*)
[root@linux ~]# cat > catfile < somefile
~/list,如何下指令?
ls -al / > ~/list 或 ls -al / 1> ~/list
~/list,如何下指令?
ls -al / >> ~/list 或 ls -al / 1>> ~/list
~/listerr,如何下指令?
ls -al /csie 2> ~/listerr
~/list 及 ~/listerr,如何下指令?
ls -al / /csie > ~/list 2> ~/listerr 或 ls -al / /csie 1> ~/list 2> ~/listerr
~/list 及 ~/listerr,如何下指令?
ls -al / /csie >> ~/list 2>> ~/listerr 或 ls -al / /csie 1>> ~/list 2>> ~/listerr
~/list,如何下指令?
ls -al / /csie > ~/list 2>&1
~/list,如何下指令?
ls -al / /csie >> ~/list 2>&1
Next: 連續命令
Up: 資料導向與管線處理
Previous: 資料導向與管線處理
Contents
2017-06-14