0

Im hoping that someone can help me, I need to remove spaces (not replace with underscores) from several thousand files on a system with cygwin. Can I do this from the shell using rename or mv somehow?

Currently:

file one.mp3
file two.mp3

All files need to become:

fileone.mp3

filetwo.mp3

Thanks

4

2 回答 2

1

默认的 Cygwin shell 是 bash,所以...

试试这个命令行,将 $DIR 替换为您要在其下执行所述转换的目录,然后检查输出:

find $DIR -type f -name '* *' | while read f; do d="${f%/*}"; f="${f##*/}"; echo mv "$d/$f" "$d/${f// }"; done

如果您对将要执行的命令感到满意,只需删除 mv 之前的 echo 并重复执行实际的重命名。请注意,这只会重命名文件,而不是目录。

于 2010-11-22T10:41:38.717 回答
0

除了上面更改文件名的答案之外,这里是更改目录名的代码:

find $DIR -type d -name '* *' | while read f; do d="${f%/*}"; f="${f##*/}"; echo mv "$d/$f" "$d/${f// }"; done

唯一的区别是从行首开始的第四个参数。字母“f”改为“d”,分别对应文件和目录。

于 2013-02-26T18:50:12.333 回答