1

A friend of mine took the liberty to remove all white-spaces " " in the foldernames on our shared drives and substitute them with the underline character "_" . The filenames are unaffected, and the error is systematic propagated in foldernames only

Any good proposal on which command could resolve this?

Thanks..!

root-11
  • 1,092
  • 1
    Why do you want to put the white spaces back in? Names without white space are much easier to work with in the terminal as well as other things – cosmorogers Dec 06 '11 at 11:39
  • Possible duplicate of http://askubuntu.com/questions/33626/how-do-i-find-all-files-in-a-folder-recursively-by-the-specific-name-and-rename – Caesium Dec 06 '11 at 12:01
  • Also see http://stackoverflow.com/questions/6911301/rename-multiple-files-shell/6911389#6911389 – cweiske Dec 13 '11 at 10:14

2 Answers2

2

If you really want to go back to spaces, here is the command, only for files

find /path -type f -iname '*_*' -exec bash -c 'echo mv -i "$1" "${1//_/ }"' _ {} \;

This only shows what would do, remove the echo to really exec.

Next you can change also directory substituting -type f with -type d.

enzotib
  • 93,831
  • This worked perfectly: find -type d -iname '_' -exec bash -c 'mv -i "$1" "${1//_/ }"' _ {} ;

    Thank you enzotib!

    – root-11 Dec 06 '11 at 16:09
2

Use the rename tool:

$ rename "_" " " */*/ */*/*/
cweiske
  • 3,307