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

前端 未结 6 502
温柔的废话
温柔的废话 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:13

    There is a proper way to split the filename and the extension: Extract filename and extension in Bash

    You can apply it like this:

    date=$(date +"%m%d%y")
    for FILE in folder1/*.csv
    do
        bname=$(basename "$FILE")
        extension="${bname##*.}"
        filenamewoext="${bname%.*}"
        newfilename="${filenamewoext}${date}.${extension}
        cp folder1/${FILE} folder2/${newfilename}
    done
    

提交回复
热议问题