• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 47
  • Last Modified:

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,
0
abubelal
Asked:
abubelal
  • 4
  • 4
3 Solutions
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
 
abubelalAuthor Commented:
Thank you; as you have tested, I will test them on my end and get back.
0
 
abubelalAuthor Commented:
Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now