Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 append a new line to a text file followed by current date and time?

share|improve this question
up vote 4 down vote accepted
echo "text" >> file
date >> file

If you want to have just in one line

echo -n "text" >> file
date >> file
share|improve this answer
How can I append line breaks? Is there a way that I can pull this off with just one line of commands? – Jon Doe Jan 6 '11 at 13:41
@jon-doe You can append line breaks by using echo - by default, it sends a line break; if you want more, you would do (for adding 4 line breaks) echo -e '\n\n\n'. To do it in one line, you can use braces { echo "text"; echo date; } >> file. – Shawn J. Goff Jan 6 '11 at 14:07
Adding curly braces didn't work for me. But adding parenthesis worked out. I'm on Ubuntu 12.04. This is what I used - (echo -n "test : "; date;) >> file.log – JohnP Nov 8 '14 at 6:37

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.