Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming file with timestamp

Status
Not open for further replies.

itr0754

Technical User
Dec 17, 2002
58
PR
This should be an easy one but I'm kind of stuck. I'm working on a simple script and I need to rename a file using the current date and I'm not sure how to do it.

Let me explain,

My file is named: testfile.txt
I want to rename it to: testfile20051122.txt
(20051122 represents yyyymmdd)

Obviously, I'm not talking about using "mv" to rename the file. I need my script to read the system date and rename the file for me. Can someone help ?? I know this one should be extremely easy for you hard-core scripters out there.
 
date +%Y%m%d will give you the format. Therefore:

mv testfile.txt testfile`date +%Y%m%d`.txt

will give you the filename - note the backticks (above the tab key on my keyboard), not apostrophes.
 
Awesome !! That's exactly what I was looking for .. Truly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top