要将 OS X 服务器的内容传输到 NTFS 兼容服务器,我需要清理所有文件名,保留原始时间戳。
我已经得到了以下命令:
1- 重命名命令 (OS X 版本)首先:brew install rename
find "$1" -print0 | xargs -0 rename 's/[\\:*?"<>|]/-/g'
2- 保留时间戳:
touch -r "$1" reference.tmp; mv -- "$1" "$2"; touch -r reference.tmp -- "$2"; rm reference.tmp
有谁知道我如何将两者结合到一个脚本中......? 感谢所有帮助! :)
最佳答案
通过 brew install rename
( http://plasmasturm.org/code/rename/ ) 安装的重命名似乎默认保留了 mtime、atime 和 ctime,以及创建时间。
$ touch a
$ stat -f'%m %a %c %B' a
1385979835 1385979835 1385979835 1385979835
$ rename s/a/b/ *
$ stat -f'%m %a %c %B' b
1385979835 1385979835 1385979835 1385979835
你也可以使用这样的命令:
for f in **/*; do mv -- "$f" "${f//[\\:*?\"<>|]/-}"; done
**
需要 bash 4.0 或更高版本和 shopt -s globstar
。
关于Linux/OS X 重命名保留时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20324851/