Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a file in unix or linux based on variable value ?


If I store date in a variable in linux,

YESTERDAY=`date --date='1 day ago' '+%d-%m-%Y'`

it will store value to YESTERDAY as 27-1-2010.

Here I want to create file as name of 27-1-2010,

How can I create file with variable 'YESTERDAY' ?

i want appending operation too. How can i do this ?

share|improve this question
Unless you've got a compelling reason (as in, some application already expects this date format), please do it Y-m-d and keep yourself sane. d-m-Y never sorts right, and over time, you'll be very upset. – Matt Simmons Feb 2 '10 at 4:45
@Matt Simmons , Thanks i will change at my real time usage. – Kumar Feb 2 '10 at 5:29


echo "something" > $YESTERDAY

to append:

echo "something" >> $YESTERDAY
share|improve this answer

I don't see anything wrong with echo "foo" >> $YESTERDAY or cat otherfile >> $YESTERDAY

What are you trying to cat? Or alternately what are you trying to put into the file called 27-1-2010?

share|improve this answer
up vote 1 down vote accepted

YESTERDAY=date --date='1 day ago' '+%d-%m-%Y'


It too working well with appending operation

share|improve this answer

You can use the variable $YESTERDAY in commands. Like touch $YESTERDAY, mv original_file $YESTERDAY

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.