0

Im trying to rename some files with the format Week_XX_2018-XX-XX_-_2018-XX-XX.md to Week_XX_2018-XX-XX/2018-XX-XX.md. So changing _-_ to /.

I tried to use rename and first tested it with the -n option. This works fine and shows something like this for all the files:

$ rename -n 's/_-_/\//g' *
rename(Week_01_2018-12-03_-_2018-12-09.md, Week_01_2018-12-03/2018-12-09.md)
...

However, when executed without the -noption the command fails. It says

Can't rename Week_01_2018-12-03_-_2018-12-19.md Week_01_2018-12-03/2018-12-09: No such file or directory

Why does this happen? How can the test of the command work but not the actual command?

ypnos
  • 50,202
  • 14
  • 95
  • 141
Trizuz
  • 15
  • 3
  • 1
    This has nothing to do with `bash`; `rename` is an external program (and there are at least two different versions of it, each taking different arguments). – chepner Oct 22 '19 at 13:07
  • @JohnKugelman I don't edit tags to criticize OP; tags are used as a tool to draw in people who can best answer a question. I feel the tags related to the core issue better serve this purpose. P.s.: Sorry I accidentially reverted your revert. – ypnos Oct 22 '19 at 13:16

1 Answers1

1

The character '/' is special as it is used as path delimiter. See Is it possible to use "/" in a filename? for a more detailed answer on why your rename fails.

ypnos
  • 50,202
  • 14
  • 95
  • 141