3

I usually rename files and directories with the mv command. I'm reading a book on bash shell that mentions the rename command. When I executed man rename a man page was shown. However, when I entered rename on bash shell, it reported:

-bash: rename: command not found

I did some research and discovered that you can install the rename command with Homebrew.

  • Is there any good reason not to install it with Homebrew?

  • Is there anything you can do with the rename command that you can't do with the mv command?

I'm also curious to know if there is a known explanation for why the rename command doesn't exist in the first place. And why is there a man page for a command that does not exist?

UPDATE: It appears that with the rename command you can do regexes like so:

rename 's/(.*)(.*)/new$1$2/' *

With mv, this doesn't appear to be possible.

  • After some more searching, I discovered that the reason there is a man page is because it is documenting a BSD system call, not the command. My question asks about installing this utility with homebrew, so it is applicable to the mac. – StevieD Aug 21 '18 at 3:15
6

In the default install of macOS, rename man page is available in the section 2. As you can notice from the man page, rename is not a command but a BSD system call.

The Homebrew formula named rename is a Perl script. You should be fine with installing it. In-fact it can give you much more flexibility than plain mv command.

After you have installed rename utility via Homebrew, running man rename will show the man page for the installed utility and not the BSD system call.

I'm also curious to know if there is a known explanation for why the command does not exist in the first place.

rename is not a standard Unix command.

And why is there a man page for a command that does not exist?

As mentioned above, the man page present refers to the system call by the same name.

  • Just saw your answer after installing it with homebrew. Now man rename bring up documentation for the "User Contributed Perl Documentation" for the utility. – StevieD Aug 21 '18 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .