我有一个你可以尝试的旧脚本 - 像
splat“wid”“wod”“wid *”[do]
wid_popup.c - > wod_popup.c
wid_popup.h - > wod_popup.h
wid_splash.c - > wod_splash.c
wid_splash.h - > wod_splash.h
如果重命名有意义,只需将“do”添加到args即可。可能有更短的方法来做到这一点,但嘿,它对我有用8)
#!/bin/sh
#
# splat-name "pattern" "replacement" "files" [do]
#
# Searches for <pattern> in the matching filenames and uses sed to replace
# with <replacement> in the same filename. i.e. it renames parts of files.
#
# Nothing is done unless [do] is added, so you can test out that it works.
#
if test $# -lt 3
then
echo
echo "Performs recursive file name changes"
echo
echo "usage: splat-name \"<pattern>\" \"<replacement>\" \"<files>\" [do]"
echo
echo "e.g:"
echo " splat \"rm\" \"remove\" \"Makefile\""
echo "Then when sure it works:"
echo " splat \"rm\" \"remove\" \"Makefile\" do"
echo
echo "splat $*"
exit
fi
TOP=/tmp
mkdir -p $TOP 2>/dev/null
pattern=$1
replacement=$2
doit=$4
svn=$5
echo "### Building pattern..."
echo "### replacement= " $replacement
echo "### pattern = " $pattern
SPLATFILE=${TOP}/.splatfile$$
SPLATFILE_TMP=${TOP}/.splatfile_tmp$$
SPLATLIST=${TOP}/.splatlist$$
SPL=${TOP}/.spl$$
###############################################################################
# Build our complex sed line
###############################################################################
echo "s/$pattern/$replacement/g" > ${SPLATFILE}
###############################################################################
# Need a newline for sed
###############################################################################
echo "" >> ${SPLATFILE}
sed "
s/NEWLINE/\\\\012/g
s/#/\\\\#/g" ${SPLATFILE} >${SPLATFILE_TMP}
mv ${SPLATFILE_TMP} ${SPLATFILE}
echo "### Finding relevant files..."
find . -follow -name "$3" -type d -not -wholename "*.svn*" -print | sed 's/^\.\///' > ${SPLATLIST}
for i in `cat ${SPLATLIST}`
do
file=$i
newfile=`echo $file | sed -f $SPLATFILE`
if [ $newfile = $file ]
then
continue
fi
echo "### mv $i -> $newfile"
if [ "$doit" = "do" ]
then
mv $i $newfile
if [ "$svn" = "svn" ]
then
svn rm $i
svn add $newfile
fi
fi
done
find . -follow -name "$3" -type f -not -wholename "*.svn*" -print | sed 's/^\.\///' > ${SPLATLIST}
#echo "### Searching for diffs..."
for i in `cat ${SPLATLIST}`
do
file=$i
newfile=`echo $file | sed -f $SPLATFILE`
if [ $newfile = $file ]
then
continue
fi
echo "### $i -> $newfile"
if [ "$doit" = "do" ]
then
cp $i $newfile
if [ $? -eq 0 ]
then
rm $i
fi
if [ "$svn" = "svn" ]
then
svn rm $i
svn add $newfile
fi
fi
done
if [ -f ${SPL} ]
then
rm ${SPL}
fi
if [ -f ${SPLATFILE} ]
then
rm ${SPLATFILE}
fi
#echo "### Done."
find /path/to/files -type f -name "*thumb*" -exec -c bash rename {} \;
(为rename命令添加了正确的选项)。