如何在命令行上生成包含日期和时间的文件名
以下代码片段对于备份很有用,可生成包含日期和时间的唯一且可排序的文件名:
generate_filename.sh
mysqldump-$(date +%F_%H-%M-%S).sql这会生成类似这样的文件名
example_filename.txt
mysqldump-2022-03-26_20-47-01.sql它们与 Windows 和 Linux 都兼容,因为不包含像 : 这样的特殊字符
Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow