Write current date/time to a file using shell scri

2020-06-23 07:34发布

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.

标签: linux shell sh
1条回答
疯言疯语
2楼-- · 2020-06-23 08:38

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.

查看更多
登录 后发表回答