Linux sed 追加文件内容

0
22

1. a 在匹配行后面追加

  1. i 在匹配行前面追加
  2. r 将文件内容追加到匹配行后面
  3. w 将匹配行写入指定文件
  4. "^"代表行首,"$"代表行尾
  5. 不论什么字符,紧跟着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

发布回复

请输入评论!
请输入你的名字