Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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 6 '11 at 11:39
Possible duplicate of… – Caesium Dec 6 '11 at 12:01
up vote 2 down vote accepted

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.

share|improve this answer
This worked perfectly: find -type d -iname '_' -exec bash -c 'mv -i "$1" "${1//_/ }"' _ {} \; Thank you enzotib! – root-11 Dec 6 '11 at 16:09

Use the rename tool:

$ rename "_" " " */*/ */*/*/
share|improve this answer
/media/gb_01/ folders already exist$ rename "" " " */*/ */*/*/ Bareword "" not allowed while "strict subs" in use at (eval 1) line 1. – root-11 Dec 6 '11 at 16:06
be sure to get your quotes right. – cweiske Dec 6 '11 at 16:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.