当前位置:网站首页>Shell script for changing the current folder and the file date under the folder

Shell script for changing the current folder and the file date under the folder

2022-07-07 08:42:00 Chen duo meat & J

#!/bin/bash

function changeName(){
    #new=`echo $1|sed 's/^/abc/g'`
    #new=`echo $1|sed -r 's/abc(.*$)/\1/g'`
	new=`echo $1|sed -r 's/20220630/20220707/g'`
	
	## With 602 Replace at the end 
	new1=`echo $1|sed -r 's/630$/707/g'`
	## With 0601.DBF Replace similar files 
	new2=`echo $1|sed 's/0630/0707/g'`
	
    echo changeName old: $1 new: $new
    if [ $1 != $new ];then
        mv $1 $new
    fi
	
	echo changeName old: $1 new: $new1
    if [ $1 != $new1 ];then
        mv $1 $new1
    fi
	
	echo changeName old: $1 new: $new2
    if [ $1 != $new2 ];then
        mv $1 $new2
    fi
}
function travFolder(){
    #echo "travFolder start"
    flist=`ls $1`
    cd $1
    for f in $flist
    do
        #echo traverse do $f
        local old=$f
        if test -d $f
        then
            #echo "traverse dir:${f}"
            travFolder $f
            #echo "traverse rename dir:${f}"
            changeName $old # Newly added rename Folder name 
        else
            #echo "traverse file:$f"
            changeName $f
        fi
    done
    cd ../
}

param=$1
if [ -z "$1" ]
    then
    param="./20220707"
    echo "empty string: $param"
else
    param=$1
fi
cp -r ./20220630 ./20220707
travFolder $param

Save as changedate.sh file

Command execution   

sh  changedate.sh

原网站

版权声明
本文为[Chen duo meat & J]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070552022598.html