Linux bash script to copy files

烈酒焚心 提交于 2019-12-11 02:49:24

问题


I need script to copy on cron basis a list of files. Files selected on name/datetime pattern and to name of file destination must by appended data like ddmmyyy. It is not problem copy files or directory, but problem to change name of each file according to its data. May be exists some open source solution? Thanks.


回答1:


You haven't provided enough information for me to give you real working code; but you can do something like this:

file=dated_log.log
ddmmyyyy=$(read -r < "$file" ; echo "${REPLY:1:8}")
cp "$file" "$file.$ddmmyyyy"

The above will copy dated_log.log to data_log.log.30102011, assuming that the first line of dated_log.log starts with 30102011.

The Bash Reference Manual will hopefully help you adjust the above to suit your needs.



来源:https://stackoverflow.com/questions/7945656/linux-bash-script-to-copy-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!