For重命名含空格文件名

IFS=$’\n’ 定义分隔符

重命名

Rename  from to filenames。。。

from是需要改变的字符串

to改变后字符串

后面是文件名

 IFS=$’\n’; for X in `ls`;

do rename $X `echo $X | sed ‘s/ mapping coverage table/-target-coverage/g’` $X;

done

Mv

 IFS=$’\n’; for X in `ls`;

do mv -f $X `echo $X | sed ‘s/ mapping per base/-per-base/g’`;

Done

My example

#!/bin/bash

help(){

cat <<HELP

help

-h help

-f from

-t to

#-p root_path

-f from -t to  [folder1][folder2]…

HELP

exit 1

}

root_path=`pwd`

while [ -n $1 ] ; do

case $1 in

 -h) help;shift;;

 -f) from=$2;shift 2;;

 -t) to=$2;shift 2;; ## -p) path=$2;shift 2;;

 -*) echo No Such an Option;break;;

 *) break;;

esac

done

path=$root_path;

[ -z “$1” ] && help ;

[ ! -z “$1” ] && [ ! -z “$from” ] && [ ! -z “$to” ] && {

echo “rename Files From: $from To: $to”;

for FOLDER in $@

do

cd $path/$FOLDER;##和原文件在同一目录

IFS=$’\n’;##设置分割符,空格有影响

rename “$from” “$to” `ls $path/$FOLDER`;

done

echo “OK”;

}

百度大模型

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

腾讯云图