# 正确输出重定向
> 「 覆盖」
>> 「 追加」
cal > x
cp /etc/hosts .
date > hosts 「 内容覆盖」
cat hosts
cal > hosts
date >> hosts 「 追加内容 」
ifconfig eth0 >> hosts
# 错误输出重定向
2> 「 覆盖 」
2>> 「 追加 」
cal 2> hosts 「 错误信息为空 」
cat hosts
xxx 2> hosts
yyy 2> hosts
zzz 2>> hosts
cat hosts
# 正确和错误信息重定向
&> 「 覆盖 」
&>> 「 追加 」
jj &> hosts
cat hosts
cal &> hosts
cat hosts
kk &>> hosts
cat hosts
cal 2> hosts 1>&2 「 正确信息以错误信息的方式输出」
cat hosts
xx > hosts 2>&1 「 错误信息以正确信息的方式输出」
cat hosts
# 输入重定向
<
cp /etc/hosts hosts
cat hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
tr 'a-z' 'A-Z' < hosts 「 小写转大写」
# 块输入结束符 eof
<<
cat > xxxxx <<xx 「 读入键盘输入到文件以xx为结束输入符 」
> xxxx
> xx 「 eof 」
cat xxxxx 「 内容 」
xxxx
aa=999
cat > xxxxx <<EOF
> $aa 「 支持变量 」
> sssss
> EOF
a >cat xxxxx
本文详细介绍了Linux命令行中的输出和错误重定向,包括如何覆盖和追加内容,以及如何处理正确和错误信息。同时,还讲解了输入重定向和使用块输入结束符EOF的功能,帮助用户更好地管理和操作命令行输出。
63万+

被折叠的 条评论
为什么被折叠?



