<
或 <<
;
>
或 >>
;
2>
或 2>>
;
>, 1> |
標準輸出至檔案,該檔案被覆蓋或建立。 | ||
>>, 1>> |
標準輸出至檔案,該檔案被建立或累加。 | ||
command | 2> |
裝置或檔案 | 錯誤輸出至檔案,該檔案被覆蓋或建立。 |
2>> |
錯誤輸出至檔案,該檔案被建立或累加。 | ||
< |
輸入 | ||
<< |
結束的輸入字元 |
[dywang@dywmac ~]$ ls /etc/crontab /etc/crontab
[dywang@dywmac ~]$ ls /etc/dywang ls: cannot access /etc/dywang: No such file or directory
[dywang@dywmac ~]$ ls /etc/crontab /etc/dywang ls: cannot access /etc/dywang: No such file or directory /etc/crontab
[dywang@dywmac ~]$ ls /etc/crontab /etc/dywang > /dev/null ls: cannot access /etc/dywang: No such file or directory [dywang@dywmac ~]$ ls /etc/crontab /etc/dywang 2> /dev/null /etc/crontab
>
將 STDOUT 導向到檔案 lsout,再導向時檔案內的資料會被覆蓋;使用 >>
導向時則 STDOUT 會累加到檔案。
[dywang@dywmac ~]$ ls /etc/crontab > lsout [dywang@dywmac ~]$ cat lsout /etc/crontab [dywang@dywmac ~]$ ls /etc/dywang-release > lsout [dywang@dywmac ~]$ cat lsout /etc/dywang-release [dywang@dywmac ~]$ ls /etc/crontab >> lsout [dywang@dywmac ~]$ cat lsout /etc/dywang-release /etc/crontab
2>
將 STDERR 導向到檔案 lserr,再導向時檔案內的資料會被覆蓋;使用 2>>
導向時則 STDERR 會累加到檔案。
[dywang@dywmac ~]$ ls /etc/dywang 2> lserr [dywang@dywmac ~]$ cat lserr ls: cannot access /etc/dywang: No such file or directory [dywang@dywmac ~]$ ls /etc/err 2> lserr [dywang@dywmac ~]$ cat lserr ls: cannot access /etc/err: No such file or directory [dywang@dywmac ~]$ ls /etc/dywang 2>> lserr [dywang@dywmac ~]$ cat lserr ls: cannot access /etc/err: No such file or directory ls: cannot access /etc/dywang: No such file or directory
[dywang@dywmac ~]$ ls /etc/crontab /etc/dywang > lsfile 2> lsfile [dywang@dywmac ~]$ cat lsfile /etc/crontab cess /etc/dywang: No such file or directory
2>&1
。
[dywang@dywmac ~]$ ls /etc/crontab /etc/dywang > lsfile 2>&1 [dywang@dywmac ~]$ cat lsfile ls: cannot access /etc/dywang: No such file or directory /etc/crontab
<<
後接的字串 EOF 為結束輸入符號。
[dywang@dywmac ~]$ cat > catfile << EOF > 123 > 456 > 789 > EOF [dywang@dywmac ~]$ cat catfile 123 456 789
<
可以將檔案內容導向前面指令,cat 可再將收到的內容導向到 catfile。
[dywang@dywmac ~]$ cat < /etc/dywang-release De-Yu Wang Linux 6.4 release (Taiwan) [dywang@dywmac ~]$ cat > catfile < /etc/dywang-release [dywang@dywmac ~]$ cat catfile De-Yu Wang Linux 6.4 release (Taiwan)