1. a 在匹配行后面追加
  2. i 在匹配行前面追加
  3. r 将文件内容追加到匹配行后面
  4. w 将匹配行写入指定文件
  5. "^"代表行首,"$"代表行尾
  6. 不论什么字符,紧跟着s命令的都被认为是新的分隔符

示例:


 ssh默认端口改为1066
debian
sed -i  's/#Port 22/Port 1066/'  /etc/ssh/sshd_config  
sed -i  's/Port 22/Port 1066/'  /etc/ssh/sshd_config   

ubuntu
sed -i  's/Port 22/Port 1066/'  /etc/ssh/sshd_config  

在文件1.sh  首行添加:666666
sed -i "1i\666666" 1.sh       

在文件1.sh行尾加入:行尾666
sed -i '$a\666' 1.sh

sshd_config加入:/RSAAuthentication yes/(含/)
sed -i '$a/RSAAuthentication yes/' /etc/ssh/sshd_config
sshd_config加入:RSAAuthentication yes
sed -i '$a RSAAuthentication yes' /etc/ssh/sshd_config
如果觉得我的文章对你有用,请随意赞赏