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