Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I append a new line to a text file followed by current date and time?

share|improve this question

1 Answer 1

up vote 3 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
3  
@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 at 6:37

Your Answer

 
discard

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.