MAC环境下批量修改文件名
程序员文章站
2024-01-17 19:21:28
...
1、sed替换文件内容包含oldstring字符串的命令
sed -i '' "s/oldstring/newstring/g" myfile //单个文件
sed -i '' "s/oldstring/newstring/g" `grep oldstring . -rl`//当前目录下所有文件
2、替换当前目录下所有文件名包含oldstring字符串的命令
rename "s/oldstring/newstring/" *
3、替换当前目录下所有文件名与内容脚本
#!/bin/bash
echo "请输入工程名称:"
read moduleName
echo "输入的工程名称是:${moduleName}"
echo "确定:(Y/N)"
read confirm
if [ "$confirm" = "Y" ]
then
curFilePath="${PWD}"
curProjectName=${curFilePath##*/}
echo "替换文件名"
rename "s/${curProjectName}/${moduleName}/" *
rename "s/${curProjectName}/${moduleName}/" */*
rename "s/${curProjectName}/${moduleName}/" */*/*
rename "s/${curProjectName}/${moduleName}/" */*/*/*
echo "替换内容"
export LC_COLLATE='C'
export LC_CTYPE='C'
sed -i '' "s/${curProjectName}/${moduleName}/g" `grep ${curProjectName} . -rl`
echo "修改目录文件名"
cd ..
rename "s/${curProjectName}/${moduleName}/" *
else
echo "已取消"
fi
4、替换当前iOS工程目录下所有文件名与内容脚本
#!/bin/bash
echo "移除pod"
pod deintegrate
echo "请输入工程名称:"
read moduleName
echo "输入的工程名称是:${moduleName}"
echo "确定:(Y/N)"
read confirm
if [ "$confirm" = "Y" ]
then
curFilePath="${PWD}"
curProjectName=${curFilePath##*/}
echo "替换文件名"
rename "s/${curProjectName}/${moduleName}/" *
rename "s/${curProjectName}/${moduleName}/" */*
rename "s/${curProjectName}/${moduleName}/" */*/*
rename "s/${curProjectName}/${moduleName}/" */*/*/*
echo "替换内容"
export LC_COLLATE='C'
export LC_CTYPE='C'
sed -i '' "s/${curProjectName}/${moduleName}/g" `grep ${curProjectName} . -rl`
echo "安装pod"
pod install
echo "修改目录文件名"
cd ..
rename "s/${curProjectName}/${moduleName}/" *
else
echo "已取消"
fi