Shell script to copy files from one location to another location and rename add the current date to every file

前端 未结 6 493
温柔的废话
温柔的废话 2021-01-30 04:46

I have a folder in my server which contains some files. These are automated that means everyday we get new files automatically which will overwrite the old ones. So want to take

6条回答
  •  情歌与酒
    2021-01-30 05:02

    path_src=./folder1
    path_dst=./folder2
    date=$(date +"%m%d%y")
    for file_src in $path_src/*; do
      file_dst="$path_dst/$(basename $file_src | \
        sed "s/^\(.*\)\.\(.*\)/\1$date.\2/")"
      echo mv "$file_src" "$file_dst"
    done
    

提交回复
热议问题