< file means open a file for reading and associate with STDIN.
<< token Means use the current input stream as STDIN for the program until token is seen. We will ignore this one until we get to scripting.
> file means open a file for writing and truncate it and associate it with STDOUT.
>> file means open a file for writing and seek to the end and associate it with STDOUT. This is how you append to a file using a redirect.
n>&m means redirect FD n to the same places as FD m. Eg, 2>&1 means send STDERR to the same place that STDOUT is going to.
第一条命令:
cat >> /etc/ssh/sshd_config << 'EOF'
>> filename
:标准输出重定向,在此处意思是将标准输出重定向到写入到后面的filename
(默认是直接输出到终端),和>
不同的是,会seed
到文件结束位置,再写入,相当于append
文件。<< token inputs
:标准输入重定向,意思加后面的inputs
重定向为标准输入,直到匹配到token
结束。第二条命令:
/bin/sed -i 's/#Banner/Banner/' /etc/ssh/sshd_config
sed -i 's/search/replace' file
:在文件file
,搜索到search
替换为replace
。数据流重定向:
<<
:标准输入流>>
:标准输出流以输出流为例:
>>
和>
的区别:>
: 如果后面的文件不存在,系统自动创建,如果存在,则会将文件内容清空在写入数据;>>
:如果后面文件不存在,系统自动创建,如果存在,则会将数据累加到文件的最下方;/bin/sed -i 's/#Banner/Banner/' /etc/ssh/sshd_config
这行代码的作用是将
/etc/ssh/sshd_config
文件中的#Banner
替换成Banner
,也就是把注释#
去掉Linux之sed用法
推荐楼主可以看一看《鸟哥的私房菜 基础学习篇》,这里面对shell和linux的常识和基础讲得比较全面
shell中每条命令都默认有三个数据流:
标准输入
,标准输出
和标准错误
。在你的问题中:
>>
是标准输出的一种,表示追加输出。这个整体是标准输入的一种,表示‘文档在此’。
cat命令整体表示将输入的‘文档’内容追加输出至文件/etc/ssh/sshd_config
sed命令的作用是将Banner前的#号删除
>>
: 不截断文件的>
<<
: "here document"