【问题标题】:Add timestamp to filename in curl command在 curl 命令中为文件名添加时间戳
【发布时间】:2016-09-21 10:54:05
【问题描述】:

我希望在文件名使用 curl 命令从远程服务器下载后添加时间戳或日期。我知道您可以使用 -o 来指定要命名文件的名称。我见过这样的建议: -o "somefile $(date +\"%H:%M\").txt" 试图实现这一点,但我不能让它工作,它只是将文件保存为'somefile $(date',就像它不将$识别为变量一样。

有谁知道使用 curl 实现此目的的方法或是否可行?

是否有另一种方法可以创建带有日期的变量,然后将其附加到文件名上?

提前致谢。

【问题讨论】:

  • 你确定你没有使用单引号吗? -o 'some file $(date +"%H:%M").txt' 会产生你描述的行为。

标签: curl sh


【解决方案1】:

它与您展示的内容不同,效果很好:

curl -o prefix-$(date +%H-%M) http://example.com/

【讨论】:

  • Windows 11 powershell 错误Get-Date : Cannot bind parameter 'Date'. Cannot convert value "+%H-%M" to type "System.DateTime". Error: "String was not recognized as a valid DateTime." At line:1 char:23
猜你喜欢
  • 2018-09-19
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
  • 2012-01-03
  • 2021-11-30
  • 2016-07-13
  • 2020-02-04
  • 2023-03-22
相关资源
最近更新 更多