终端下有没有群改文件名的命令?
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
-
- 帖子: 283
- 注册时间: 2005-08-16 14:59
终端下有没有群改文件名的命令?
DOS下是REN,可是终端下的MV好像只能单个改,有没有别的啊?
-
- 帖子: 86
- 注册时间: 2006-03-03 18:07
#!/bin/sh
#we have less than 3 arguments.print the help text:
if [ $# -lt 3 ]; then
echo " ren --renames a number of file using sed regular expressions
USAGE: ren 'regexp' 'replacement' files ... Example: rename all *.htm in *.html: ren 'htm' 'heml' *.htm help"
exit 0
fi
OLD="$1"
NEW="$2"
# the shift command removes one argument from the list of command line arguments.
# 该命令可用来批处理修改文件后缀
# example : ren 'cc' 'c' *.cc
shift
shift
# $* comtains now all the files:
for file in $*; do
if [ -f "$file" ];then
newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"`
if [ -f "$newfile" ]; then
echo "ERROR:$newfile exists already"
else
echo "renaming $file to $newfile ..."
mv "$file" "$newfile"
fi
fi
done
不是原创,呵呵
#we have less than 3 arguments.print the help text:
if [ $# -lt 3 ]; then
echo " ren --renames a number of file using sed regular expressions
USAGE: ren 'regexp' 'replacement' files ... Example: rename all *.htm in *.html: ren 'htm' 'heml' *.htm help"
exit 0
fi
OLD="$1"
NEW="$2"
# the shift command removes one argument from the list of command line arguments.
# 该命令可用来批处理修改文件后缀
# example : ren 'cc' 'c' *.cc
shift
shift
# $* comtains now all the files:
for file in $*; do
if [ -f "$file" ];then
newfile=`echo "$file" | sed "s/${OLD}/${NEW}/g"`
if [ -f "$newfile" ]; then
echo "ERROR:$newfile exists already"
else
echo "renaming $file to $newfile ..."
mv "$file" "$newfile"
fi
fi
done
不是原创,呵呵