I have multiple files that need to be renamed with a date added to the beginning of the file name that I am trying to script.

I'm using the cp command because I need to keep the original file

I need the file to be YYYYMMDDfile.txt

I have used every timestamp configuration (date '+%Y%m%d') but am having no luck. I have no problems adding timestamp to end of file name just the beginning. What am I missing?


Not sure what you are doing wrong but the following works:

for i in *; do cp "$i" $(date '+%Y%m%d')"$i"; done

(you should only run this once in a directory)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.