例如所在目录为/abc,替换目标为其内部所有文件(含所有子目录).
替换目录下所有文件的所有字符串:
例如:http
替换为helloWold
,命令:
# cd /abc && beforeName="http";afterName="helloWorld";sed -i "s/$beforeName/$afterName/g" `grep "$beforeName" -rl ./`;
替换文件名:
例如:某目录下所有含有http
的文件或目录均换为helloWold
,命令:
# cd /abc && beforeName="http";afterName="helloWorld";for file in `find -name "*$beforeName*" -type d ` ;do newfile=`echo $file | sed "s/$beforeName/$afterName/g"`;mv $file $newfile;done;for file in `find -name "*$beforeName*" -type f ` ;do newfile=`