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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a date to the end of a filename 1

Status
Not open for further replies.

mmyers

MIS
Aug 8, 2001
25
0
0
US
Hello! I would like to take an existing filename and append the current date to it. The date format I would like to use is "date +%m%d%y%H" (without the quotes, of course). So, the end result would be "filename.07120214".

Any help is appreciated! Thanks!

Michael
 
#!/bin/ksh

file="${curFile}.$(date +%m%d%y%H)" vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Michael:

In a very simple way not worrying about pathnames and other major error checking:

#/bin/ksh
# if argument 1 is a regular file and it exists:

if [[ -f $1 ]]
then
mv $1 $1.$(date '+%m%d%y%H')
fi

Regards,


Ed
 
Great!! Thanks a lot for the help!

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top