# rename - perldoc - phpman

> **TLDR:** Rename a file or group of files with a `regex`.
>
- Replace `from` with `to` in the filenames of the specified files:
  `rename 's/{{from}}/{{to}}/' {{*.txt}}`
- Dry-run - display which changes would occur without performing them:
  `rename -n 's/{{from}}/{{to}}/' {{*.txt}}`
- Change the extension:
  `rename 's/\.{{old}}$/\.{{new}}/' {{*.txt}}`
- Change to lowercase (use `-f` in case-insensitive filesystems):
  `rename {{-f|--force}} 'y/A-Z/a-z/' {{*.txt}}`
- Capitalize first letter of every word in the name:
  `rename {{-f|--force}} 's/\b(\w)/\U$1/g' {{*.txt}}`
- Replace spaces with underscores:
  `rename 's/\s+/_/g' {{*.txt}}`

*Source: tldr-pages*

---

    rename OLDNAME,NEWNAME
            Changes the name of a file; an existing file NEWNAME will be
            clobbered. Returns true for success; on failure returns false
            and sets $!.

            Behavior of this function varies wildly depending on your system
            implementation. For example, it will usually not work across
            file system boundaries, even though the system *mv* command
            sometimes compensates for this. Other restrictions include
            whether it works on directories, open files, or pre-existing
            files. Check perlport and either the [rename(2)](https://www.chedong.com/phpMan.php/man/rename/2/markdown) manpage or
            equivalent system documentation for details.

            For a platform independent "move" function look at the
            [File::Copy](https://www.chedong.com/phpMan.php/perldoc/File%3A%3ACopy/markdown) module.

            Portability issues: "rename" in perlport.

