Linux batch rename directories and strip # characters on behalf of

I have a directory with many C # subront directories infront of them:

#adhasdk
#ad18237

I want to rename them all and delete # caracter I tried:

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

but doesn't seem to work.

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

Any ideas on this. Thanks

+3
source share
5 answers

Just use

$ rename 's/^#//' *

use -n to verify that what you think will happen will actually happen. In your example, you will find out about the wrong quotes used (reverse) in the error message

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

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

, g () , #, , .

+5

, , , "" , :

  • "-n"
  • ,

"-n" , . ( -, , ).

+3

, backticks (`). :

rename -n 's/#//g' *
+2
for DIR in \#*/
do
     echo mv "$DIR" "${DIR/#\#/}"
done
+1

I had to rename all the folders inside this folder. Each folder name had some text inside parentheses. The following command removed parentheses from all folder names:

rename 's /(.+)//' *

0
source

Source: https://habr.com/ru/post/1736309/


All Articles