osx - How can I recursively replace file and directory names using Terminal? -
using terminal on macos, want recursively replace word name of both directory , file name. instance, have angular app , module name article, of file names, , directory names contain word article. i've done find , replace replace articles apples in code. want same file structure both file names , directories share same convention.
just information, i've tried use newest yeoman generator create new files, there seems issue it. alternative duplicate directory , rename of files, quite time consuming.
got work following script
var=$1 if [ -n "$var" ]; crudname=$1 crudnameuppercase=`echo ${crudname:0:1} | tr '[a-z]' '[a-z]'`${crudname:1} foldername=$crudname's' # create new folder cp -r modules/articles modules/$foldername # find/replace in files find modules/$foldername -type f -print0 | xargs -0 sed -i -e 's/article/'$crudnameuppercase'/g' find modules/$foldername -type f -print0 | xargs -0 sed -i -e 's/article/'$crudname'/g' # delete useless files due sed rm modules/$foldername/**/*-e rm modules/$foldername/**/**/*-e rm modules/$foldername/**/**/**/*-e # rename files file in modules/$foldername/**/*article* ; mv $file ${file//article/$crudname} ; done file in modules/$foldername/**/**/*article* ; mv $file ${file//article/$crudname} ; done file in modules/$foldername/**/**/**/*article* ; mv $file ${file//article/$crudname} ; done else echo "usage: sh rename-module.sh [crud-name]" fi
apparently i'm not 1 encounter issue
Comments
Post a Comment