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

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

    cp --archive home/webapps/project1/folder1/{aaa,bbb,ccc,ffffd}.csv home/webapps/project1/folder2
    rename 's/\.csv$/'$(date +%m%d%Y).csv'/' home/webapps/project1/folder2/{aaa,bbb,ccc,ffffd}.csv
    

    Explanation:

    • --archive ensures that the files are copied with the same ownership and permissions.
    • foo{bar,baz} is expanded into foobar foobaz.
    • rename is a commonly available program to do exactly this kind of substitution.

    PS: don't use ls for this.

提交回复
热议问题