【发布时间】:2011-02-12 03:50:44
【问题描述】:
谁能推荐一个安全的解决方案,从给定的根目录开始,用下划线递归替换文件和目录名称中的空格?例如:
$ 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
【问题讨论】:
-
如果在同一目录中有一个名为
foo bar的文件和另一个名为foo_bar的文件,你想发生什么? -
好问题。我不想覆盖现有文件或丢失任何数据。它应该保持不变..理想情况下打印一个警告,但这可能要求太多了。
标签: linux bash whitespace filenames