0

I have a directory with ogg file, and want to change file names starting with i-.

What can I do? For instance, doing rename 's/i-nuovi/nuovi/g' * gave me

Unknown option: marino-barreto-cinque-minuti-ancora.ogg
Usage:
    rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ -e|-E perlexpr]*|perlexpr
    [ files ]

Something is wrong, but cannot track it down. How can I ensure that I watch i- from the beginning?

Vera
  • 1,223
  • 1
    There are a few rename implementations. Which one are you using? Have you tried rename -e 's/i-nuovi/nuovi/g' ./*? – xiota Jan 21 '23 at 04:42
  • 1
    The title says -i, but the body says i-. The first could cause problems. The second shouldn't. – xiota Jan 21 '23 at 04:43
  • 1
    Thank you for pointing out the problem with the title. I found out that some files started with - and rename interpreted that as an option. – Vera Jan 21 '23 at 05:03
  • Things are not very clear, what I know is that rename is version 0.20 – Vera Jan 21 '23 at 05:16

2 Answers2

1

If you don't demand using rename tool, this can be easily done with bash native functions/built-ins:

for-loop and parameter expansion (use man bash and search for Parameter Expansion for more info):

for ef in $(ls i-*); do mv $ef ${ef#i-}; done

If your files contain white spaces in their names you can use IFS (bash builtin also):

old_IFS=$IFS; IFS=$'\n'; for ef in $(ls i-*); do mv $ef ${ef#i-}; IFS=$old_IFS; done
Damir
  • 501
0

Different implementations of Perl's rename:

Try

rename --version

and check my link

Then

rename -n 's/^i-nuovi/nuovi/g' -- ./*.ogg
#                              ^^
#                       end of parameters

If that doesn't work, just try:

rename -n 's/^i-nuovi/nuovi/g' ./*.ogg
#                              ^^
#                       that should helps 

Remove -n (aka dry-run) when the output looks satisfactory.

  • How can I ensure the match starts from the beginning of the file? – Vera Jan 21 '23 at 05:38
  • Added ^ anchor, check new code. – Gilles Quénot Jan 21 '23 at 05:53
  • 1
    @GillesQuenot at least with my version of Perl rename (File::Rename version 1.30), ^ doesn't match at the beginning of the actual filename when the glob pattern start with ./, unless you add one of -d, --filename, --nopath, --nofullpath – steeldriver Jan 21 '23 at 14:20