To transfer the contents of an OS X server to a NTFS compatible one, I need to sanitize all filenames, preserving the original timestamps.
要将OS X服务器的内容传输到兼容NTFS的服务器,我需要清理所有文件名,保留原始时间戳。
I already got as far as the following commands:
我已经得到以下命令:
1- for the rename command (OS X VERSION) FIRST: brew install rename
1-用于重命名命令(OS X VERSION)FIRST:brew install rename
find "$1" -print0 | xargs -0 rename 's/[\\:*?"<>|]/-/g'
2- for the timestamp preserving:
2-保留时间戳:
touch -r "$1" reference.tmp; mv -- "$1" "$2"; touch -r reference.tmp -- "$2"; rm reference.tmp
Does anybody know how I could combine both into a single script..? All help kindly appreciated! :)
有谁知道如何将两者结合成一个脚本..?所有人都非常感谢! :)
1 个解决方案
#1
1
The rename that is installed by brew install rename
(http://plasmasturm.org/code/rename/) seems to preserve the mtime, atime, and ctime, and creation time by default.
通过brew安装重命名(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
You might also use a command like this:
您也可以使用如下命令:
for f in **/*; do mv -- "$f" "${f//[\\:*?\"<>|]/-}"; done
**
requires bash 4.0 or later and shopt -s globstar
.
**需要bash 4.0或更高版本以及shopt -s globstar。
#1
1
The rename that is installed by brew install rename
(http://plasmasturm.org/code/rename/) seems to preserve the mtime, atime, and ctime, and creation time by default.
通过brew安装重命名(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
You might also use a command like this:
您也可以使用如下命令:
for f in **/*; do mv -- "$f" "${f//[\\:*?\"<>|]/-}"; done
**
requires bash 4.0 or later and shopt -s globstar
.
**需要bash 4.0或更高版本以及shopt -s globstar。