linux中的I/O重定向
- 標准輸入 (stdin): 代碼為0,使用<或<<;
- 標准輸出 (stdout): 代碼為1,使用>或>>;
- 標准錯誤輸出(stderr): 代碼為2,使用2>或2>>;
- ">" ">>"
>: 覆蓋輸出
>>:追加輸出 # set -C 禁止對已經存在文件使用覆蓋重定向;強制覆蓋輸出,則使用 >| # set +C 關閉上述功能
- "2>" "2>>"
2>: 重定向錯誤輸出
2>>: 追加方式
將正確的與錯誤的分別存入不同的文件中
# ls / /varr > /tmp/var3.out 2> /tmp/err.out # ls /varr > /tmp/var4.out 2> /tmp/var4.out /dev/null垃圾桶黑洞裝置 &>: 重定向標准輸出或錯誤輸出至同一個文件(或者2>&1)
- "<"
輸出重定向(將原來需要由鍵盤輸入的數據,改由文件內容來取代)
# tr 'a-z' 'A-Z' < /etc/fstab
- "<<"
Here Document(代表結束的輸入字符)
# cat << END # cat >> /tmp/myfile.txt << EOF
/dev/null, 軟件設備,bit bucket,數據黑洞,將內容輸出定向到該設備下無任何返回內容
轉自 :https://www.linuxprobe.com/refre-gd-he.html
-------------------------------------------------------------------------
在某些極端的機器上,我們使用/etc/rc.local配置開機自啟會莫名其妙不生效,所以我們可以采取曲線救國的辦法,使用crontab來實現開機自啟。
使用方法:
crontab -e @reboot /home/start.sh
保存即可。
@reboot 表示重啟開機的時候運行一次。還有很多類似參數如下:
string meaning ------ ----------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once a week, "0 0 * * 0". @daily Run once a day, "0 0 * * *". @midnight (same as @daily) @hourly Run once an hour, "0 * * * *".
配置完成后,會在開機后進行啟動,如果需要延時啟動,可以參考:
@reboot sleep 300 && /home/start.sh
參考文章:http://www.debianhelp.co.uk/crontab.htm