任何人都可以推薦一個安全的解決方案,以遞歸方式從給定的根目錄開始,用文件和目錄名稱中的下劃線替換空格嗎?例如,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