Gabriel Solomon Gabriel Solomon - 9 months ago 37
Linux Question

linux batch rename directories and strip # character from name

i have a directory with a lot of subdirectories with a # infront of them:


I want to rename them all and remove the # caracter
I tried to do:

rename -n `s/#//g` *

but didn't seem to work.

-bash: s/#//g: No such file or directory

Any ideas on this.

Answer Source

Just use

$ rename 's/^#//' *

use -n just to check that what you think it would happen really happens. In you example you have the clue about the wrong quotes used (backticks) in the error message

 -bash: s/#//g: No such file or directory

bash is trying to execute a command named s/#//g.

No that using g (global) and not anchoring the regular expression you will replace any #, not just the one in the first position.