Mike Conigliaro

Appending command output to a timestamped logfile (Linux vs Windows)

In Linux, it’s easy to log the output of a command to a timestamped log file:

echo this is easy >> $(date +%s).log

When I tried to accomplish the same thing in Windows, I ended up with this mess:

for /f "tokens=1,2,3,4 delims=/- " %%a in ("%date%") do set ts=%%d%%b%%c
echo this sucks >> %ts%.log
blog comments powered by Disqus