ubuntu系统批量修改文件内容

代码作用:
./bin/目录下的/ly/code替换为/lby
格式为:

sed -i "s/旧内容/新内容/g" `grep 旧内容 -rl 文件名`

下面代码的\表示转义

#!/bin/bash

#1.变量定义
directory="./bin/"

#2.遍历子目录
for file in `ls $directory`
do
        if [ -d $directory/$file ]
        then
        		# 如果是一个目录
                echo $file is dir
        else
        		# 如果是可修改的文件
                sed -i "s/\/ly\/code/\/lby/g" `grep \/ly\/code -rl ./bin/$file`
                echo $file is file
        fi
done

猜你喜欢

转载自blog.csdn.net/weixin_44669966/article/details/126391691
今日推荐