Shell 中冒号变成了斜线

2019-12-24 22:19:36 +08:00
 JamesHopbourn

james$ touch test
james$ cp test "test $(date "+%Y:%m:%d %H:%M")"
james$ ls
test test 2019:12:24 22:13

本想用 cp 做备份,格式化输出:年-月-日 时:分。但是在 $(date) 中的 : 会变成 / 。 在 ls 中查看是 test 2019:12:24 22:13,但是实际桌面看到是:test 2019/12/24 22/13,我的预期结果是:test 2019/12/24 22:13

请问是否有解决办法?我试过 \ 但是并没没用

6043 次点击
所在节点   Bash
4 条回复
ynyounuo
2019-12-24 22:25:44 +08:00
JamesHopbourn
2019-12-24 22:33:36 +08:00
@ynyounuo 这个想到过,但是试过了,会报错
james$ cp test "test $(date "+%Y:%m:%d %H'/'%M")"
cp: test 2019:12:24 22'/'32: No such file or directory

james$ cp test "test $(date "+%Y:%m:%d %H/%M")"
cp: test 2019:12:24 22/33: No such file or directory
ynyounuo
2019-12-25 05:33:07 +08:00
@JamesHopbourn 额…… 你真的点开看了吗
JamesHopbourn
2019-12-25 08:48:24 +08:00
@ynyounuo 懂了 谢谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/632004

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX