任何人都可以推荐一个安全的解决方案,以递归方式从给定的根目录开始,用文件和目录名称中的下划线替换空格吗?例如,Bash递归地替换名称上的很多空格
$ 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
我已经复制由是最主要的问题其他用户的问题,但我需要添加另外一个问题:
我使用解决方案如下:
$ find -depth -name '* *' -execdir rename " " "_" {} +;
它的工作原理,但只取代在项目(目录或文件)上找到的第一个空格。任何关于如何使循环寻找空间并在全部消失时停止的想法?
下面的解决方案适用于我。我刚刚添加了-depth选项。没有它,父目录的名称已更改并且进程崩溃。 谢谢! – 2014-11-05 20:40:36