shell命令求解

先贴命令

cat >> /etc/ssh/sshd_config << 'EOF'
KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org
EOF

cat我知道是查看文件的意思,可是这条>> 和 << 是什么意思呢,求教

还有一句:

/bin/sed -i 's/#Banner/Banner/' /etc/ssh/sshd_config

求解命令

阅读 4k
5 个回答

第一条命令:
cat >> /etc/ssh/sshd_config << 'EOF'

  1. >> filename:标准输出重定向,在此处意思是将标准输出重定向到写入到后面的filename(默认是直接输出到终端),和>不同的是,会seed到文件结束位置,再写入,相当于append文件。

  2. << token inputs:标准输入重定向,意思加后面的inputs重定向为标准输入,直到匹配到token结束。

表达能力有限,直接看下面吧

< 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. 

第二条命令:
/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中每条命令都默认有三个数据流:标准输入标准输出标准错误
在你的问题中:>>是标准输出的一种,表示追加输出。

<<'EOF'
xx
oo
EOF

这个整体是标准输入的一种,表示‘文档在此’。

cat命令整体表示将输入的‘文档’内容追加输出至文件/etc/ssh/sshd_config


sed命令的作用是将Banner前的#号删除

<<是重定向
sed是文本分析的命令,具体的需要百度了

>>: 不截断文件的>

<<: "here document"

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题