问题
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