Writing current date / time to file using shell script

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

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

It will say that it is complete, but nothing is printed after it starts.

+3


source to share


1 answer


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

.

As I tried on my system: -

date > /tmp/date.txt

... And the file contains Wed Apr 5 09:27:37 IST 2017

.



[Edit] There is a difference between → (append to file) and> (Create new file)

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

.

+2


source







All Articles