使用Shell脚本将当前日期/时间写入文件 [英] Write current date/time to a file using shell script
问题描述
我正在尝试使用Shell脚本将当前日期和时间写入文件.这是我到目前为止所拥有的
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.
推荐答案
使用 date>>//home/user/Desktop/Scripts/Date Logs/datelog.txt
.
就像我在系统中尝试过的一样:-
Like i tried in my system :-
日期>/tmp/date.txt
.文件包含 Wed Apr 5 09:27:37 IST 2017
.
>>(附加到文件)和>(创建新文件)之间有区别
There are difference between >>(appending to the file) and >(Create the new file)
-如chepner所建议,您可以使用 date>>直接将date命令的o/p重定向到文件./tmp/date.txt
.
- As suggested by chepner, you can directly redirect the o/p of date command to file using date >> /tmp/date.txt
.
这篇关于使用Shell脚本将当前日期/时间写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!