Write current date/time to a file using shell script

情到浓时终转凉″ 提交于 2020-05-12 04:42:42

问题


I am trying to use a shell script to write the current date and time to a file. Here is what I have so far

echo "$(date)" >> //home/user/Desktop/Scripts/Date Logs/datelog.txt

It will say it completed but nothing is printed to the file after it is run.


回答1:


Use date >> //home/user/Desktop/Scripts/Date Logs/datelog.txt.

Like i tried in my system :-

date > /tmp/date.txt. And file contains Wed Apr 5 09:27:37 IST 2017.

[Edit] There are difference between >>(appending to the file) and >(Create the new file)

Edit:- As suggested by chepner, you can directly redirect the o/p of date command to file using date >> /tmp/date.txt.



来源:https://stackoverflow.com/questions/43221469/write-current-date-time-to-a-file-using-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!