bash - 根据 MacOS 文件夹中的文件名更改文件创建和修改的日期和时间
问题描述
我在文件夹中有很多文件,文件名如下
20190618_213557.mp4
20190620_231105.mp4
20190623_101654.mp4
..
我需要在终端中使用 bash 脚本根据文件名 20190618_213557=YYYYMMDD_HHMMSS 更改创建日期和时间
解决方案
MACOS Uses touch -mt to change file creation/modification time. Here is the script:
#!/bin/bash
FILES="/Users/shakirzareen/Desktop/untitledfolder/*"
for f in $FILES ## f = full path + filename
do
t="${f##*/}" ##remove folder path from filename
t2="${t//_}" ##remove _ from filename
t3="${t2%%.*}" ##remove file extension part
touch -mt "$t3" $f ##set creation and modification time of file
done
推荐阅读
- python - 主函数不运行该函数
- gitlab - Gitlab:如何在标记的版本/发布上运行部署作业?
- javascript - 错误:混合内容:____' 处的页面已通过 HTTPS 加载,但请求了不安全的 XMLHttpRequest 端点 此请求已被阻止
- sql - 从时间戳列中获取月份名称
- java - 如何在 tomcat 服务器中更改 tls 版本?
- wordpress - wp-admin webiste主页的索引打开但wp-admin未打开
- c# - c#中yield return的操作数
- docker - Docker-compose 无效。不允许附加属性
- typescript - 从 node_modules 导入项目根目录中的文件
- in-app-purchase - 如何制作应用内购买试用版应用