Suffix a file name with system date

Hi, Experts:
What are the commands to suffix file names with system date, date/time
in this format __YYYYMMDD.txt  and _YYMMDD_HHMM.txt as new files in same dir.

Example:
File1.txt remains; a new file created as File1_20150512.txt
File2.txt remains; a new file created as File2_20150512_0904.txt

Thanks,
abubelalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
date:

cp File1.txt File1_$(date "+%Y%m%d").txt

date/time:

cp File2.txt File2_$(date "+%Y%m%d_%H%M").txt
0
ozoCommented:
cp File1.txt File1_`date +%Y%m%d`.txt
cp File2.txt File2_`date +%Y%m%d_%H%M`.txt
0
woolmilkporcCommented:
If the original filenames should be variable:

FILE=File1.txt

cp $FILE ${FILE/\./$(date +"_%Y%m%d.")}

FILE=File2.txt

cp $FILE ${FILE/\./$(date +"_%Y%m%d_%H%M.")}

It's tested, as always.
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

abubelalAuthor Commented:
Thank you; as you have tested, I will test them on my end and get back.
Pl. let me know if you revise them.
0
woolmilkporcCommented:
Talking about revisions:

Did you notice that I had to edit my last solution in order to change the wrong colon ( : ) to the correct underscore ( _ ) ?
0
abubelalAuthor Commented:
Pl. paste the one liner final command date version again to be safe, thx
0
woolmilkporcCommented:
Date:

FILE=File1.txt
cp $FILE ${FILE/\./$(date +"_%Y%m%d.")}

Date/time:

FILE=File2.txt
cp $FILE ${FILE/\./$(date +"_%Y%m%d_%H%M.")}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abubelalAuthor Commented:
Thank you; as you have tested, I will test them on my end and get back.
0
abubelalAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.