I'm working on a batch file for my program's setup.

I want to make a log from the batch file that logs the run time and date I created:

     echo Setup Run Log
     echo The setup was runned at %time% on %date% by %username%.

But every time the code runs it over writes the information in the file. I want that the first time the batch starts a run.log file to be created that has Setup Run Log and every other time the batch runs the time, date and username be written on the line below a line that already has something written.

My question: How to output to the last line in a file.

  • Could you please clarify what operating system and what batch file system you are using? Do you mean the batch system in some version of Windows?
    – Daniel K
    May 27, 2019 at 17:26
  • To append to a file double the redirection symbol >>
    – LotPings
    May 27, 2019 at 17:31

1 Answer 1


Instead of doing (command) > run.log, change your code to (command) >> run.log.

">" redirects and overwrites. ">>" appends the content.

More details about command redirection is at https://www.tldp.org/LDP/abs/html/io-redirection.html.

  • Thank you, all this time I'm creating batch files I didn't know the difference between > and >>.
    – Ali
    May 27, 2019 at 18:00
  • As it happens, your answer is correct.   But your reference is dead wrong; the question is about a CMD batch file on Windows.   (Even for Unix / Linux / Bash, though, TLDP is not a great reference.) May 27, 2019 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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