搜索
linux - shell命令求解
PHPz
PHPz 2017-04-17 17:04:55
[Linux讨论组]
PHPz
PHPz

学习是最好的投资!

全部回复(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的常识和基础讲得比较全面

ringa_lee

shell中每条命令都默认有三个数据流:标准输入标准输出标准错误
在你的问题中:>>是标准输出的一种,表示追加输出。

<<'EOF'
xx
oo
EOF

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

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


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

PHPz

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

大家讲道理

>>: 不截断文件的>

<<: "here document"

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号