Context: router outfitted with Merlin AsusWRT. The goal is to append the epoch time to a text file from the UNIX command-line within router. Example:


The date command return Unix Epoch Time

date +%s

Is there a clever one-liner command that can append the Epoch time?

Attempts to assign the output to a variable were not successful, from the UNIX command line:

myVariable = date +%s

closed as unclear what you're asking by Michael Homer, schily, Jeff Schaller, Archemar, meuh Jul 24 '18 at 13:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • In what language? Do you want the output of date +%s or date +'{date:%s}' stored in a variable? Where does the text file come into play? – Stéphane Chazelas Jul 23 '18 at 18:41
  • @StéphaneChazelas Thanks for the good questions: I have updated the OP. A UNIX .sh script records data in a text file and the goal is to append the Epoch time to each measurement record (not discussed in OP). If it is not necessary to save the date to a variable to append it to the text file, that's fine – gatorback Jul 23 '18 at 19:48


myVariable=`date +%s`

or preferably:

myVariable=$(date +%s)

the one-liner: {date +%s} returned {1532368565}.
the one-liner: {$(date +%s)} returned {1532368565}.

One-liner that appends to a data file:

echo {`date +%s`} >> myDataFile.txt
echo {$(date +%s)} >> myDataFile.txt
  • it will be worth if we wanted to use nested variables $(echo $(foo)). – msp9011 Jul 23 '18 at 18:14

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