任何人都可以推荐一个安全的解决方案,从给定的根目录开始递归地用下划线替换文件和目录名称中的空格吗?例如:
$ tree
.
|-- a dir
| `-- file with spaces.txt
`-- b dir
|-- another file with spaces.txt
`-- yet another file with spaces.pdf
变成:
$ tree
.
|-- a_dir
| `-- file_with_spaces.txt
`-- b_dir
|-- another_file_with_spaces.txt
`-- yet_another_file_with_spaces.pdf
原文由 armandino 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
rename
(又名prename
)这是一个 Perl 脚本,可能已经在您的系统上。分两步进行:基于 Jürgen 的 回答,并且能够使用
/usr/bin/rename
(Perl 脚本)的“Revision 1.5 1998/12/18 16:16:31 rmb1”版本在一个范围内处理多层文件和目录: