OS X终端命令创建一个在当前日期命名的文件(OS X terminal command to create a file named on current date)

编程入门 行业动态 更新时间:2024-10-28 17:15:08
OS X终端命令创建一个在当前日期命名的文件(OS X terminal command to create a file named on current date)

我已经设置了一个cron任务,我想将输出保存到一个文件中。 该文件应该具有基于cron执行时间的名称(例如:20110317-113051.txt)。

我的实际cron命令如下所示:

lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txt

我希望textfile被某种独特的时间戳取代。

我试过了

lynx -dump http://somesite/script.php > $(date).txt 但是我收到一条命令不明确的错误。

谢谢你的帮助!

索林

I have set up a cron task and I want to save the output to a file. The file should have the name based on the time at which the cron was executed (eg.: 20110317-113051.txt).

My actual cron command is as follows:

lynx -dump http://somesite/script.php > /Volumes/dev0/textfile.txt

I want the textfile to be replaced by some sort of unique time stamp.

I've tried

lynx -dump http://somesite/script.php > $(date).txt but I receive an error that the command is ambiguous.

Thanks for your help!

Sorin

最满意答案

date命令可以给出一个格式来确定它生成日期的确切格式。它看起来好像你想要$(date +%Y%m%d-%H%M%S).txt 。 使用这种格式, date的输出应该没有空格,括号等,否则可能会混淆shell或lynx命令。

有关date命令和http://developer.apple.com/library/的文档,请参见http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/date.1.html 。 mac /#documentation / Darwin / Reference / ManPages / man3 / strftime.3.html以获得格式字符串的文档,这与标准库中的strftime函数相同。

The date command can be given a format to determine exactly what form it generates dates in. It looks as if you want $(date +%Y%m%d-%H%M%S).txt. With this format, the output of date should be free of spaces, parentheses, etc., which might otherwise confuse the shell or the lynx command.

See http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/date.1.html for documentation of the date command and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/strftime.3.html for documentation of the format string, which is the same as for the strftime function in the standard library.

更多推荐

本文发布于:2023-04-27 19:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1328596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:终端   创建一个   命令   日期   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!