#!/bin/bash
print_error_info(){
cat <<ERROR_EOF
error !
use option h to get help infomation
ERROR_EOF
}
st=0
while getopts "s:p:h" OPT
do
case $OPT in
s)
st=$OPTARG
;;
p)
path=$OPTARG
;;
h)
cat <<HELP_EOF
DESCRIPTION
This script changes the name of files under directory specified by option p to continuous number which starts from
a number specified by option s. The extension name of the file won't be changed
OPTIONS
-s
specify the initiating number
-p
specify the directory in which files that will be changed reside
-h
output this help document
HELP_EOF
exit 0
;;
esac
done
if [ -z "$path" ] ; then
print_error_info
exit 1
fi
cnt=0
find "$path" -maxdepth 1 -type f | while read line
do # www.jb200.com
name=$(basename $line)
echo $line
if [ $(echo $name |
linuxjishu/13830.html target=_blank class=infotextkey>awk '{ print match($0, "."); }') -eq "0" ]; then
name="$cnt"
else
name="$cnt"."$(echo $name | awk -F . '{ print $NF }')"
fi
name="$(dirname $line)"/$name
mv $line $name
let "cnt=$cnt+1"
done