遞歸遍歷子目錄改後綴名(批量文本改名rename)

#!/bin/sh
oldsuffix="txt"
newsuffix="sql"
dir=$(eval pwd)



function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then 
            getdir $dir_or_file
        else
            suffix=$(ls ${dir_or_file} | cut -d. -f2)
	    echo "$suffix \n" 
	    if [ "$suffix" = "txt" ] 
	    then
	        name=$(ls ${dir_or_file} | cut -d. -f1 )
	        mv $dir_or_file ${name}.${newsuffix}
	    fi
	    
	fi  
    done
}

root_dir="/Users/me/xxx/temp_whole_253_OSS-KEY-lfhbcxrsjrx26p5n20c8zz28"
getdir $root_dir
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章