1826414 Members
4082 Online
109692 Solutions
New Discussion

Re: file name with date

 
mario_43
Occasional Contributor

file name with date

Hi folk,

I'd write a file name with the date at the end from a script, for example:
file_name_030818
I tried with:
DATE= date +%y%m%D
touch file_name_$DATE

but DATA doesn't have the correct value
What I've to do?
Thanks in advance,
M
8 REPLIES 8
Michael Kelly_5
Valued Contributor

Re: file name with date

Mario,
try
DATE=`date +%y%m%D`

note the backticks and no spaces arounr the =

HTH,
Michael.
The nice thing about computers is that they do exactly what you tell them. The problem with computers is that they do EXACTLY what you tell them.
Jean-Luc Oudart
Honored Contributor

Re: file name with date

initialise DATE with :
DATE=$( date +"%y%m%d")

Rgds,
JL
fiat lux
Vitek Pepas
Valued Contributor

Re: file name with date

Try this:
DATE=$(date +%Y%M%d)
touch file_name_$DATE
Bryan D. Quinn
Respected Contributor

Re: file name with date

Hey Mario,

Try:

DATE=`date +%y%m%d`

touch file_name_$DATE

That should take care of it.

-Bryan
Helen French
Honored Contributor

Re: file name with date

Try the single line:

# touch file_name_`date +%y%m%d`

OR if you want it with variables:

DATE=`date +%y%m%d`
touch testfile_$DATE
Life is a promise, fulfill it!
Pete Randall
Outstanding Contributor

Re: file name with date

Mario,

I think you need to choose another format for your date variable. The way you have it, there are forward slashes present in the date and you are unable to create a file name with the slashes in it.


Pete


Pete
Geoff Wild
Honored Contributor

Re: file name with date

I do something like:

ftplog="/tmp/${scrname}.ftplog.`/bin/date +%y%m%d%H%M%S`"

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Paul Sperry
Honored Contributor

Re: file name with date

touch file_name_`date +"%y%h%d"`