-1

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?

1 Answer 1

3

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)

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.