rename - renames multiple files
rename [-bfivnl] [-S backup-suffix] [-V {numbered,existing,simple}] [--backup] [--force] [--interactive] [--verbose] [--suffix=backup-suffix] [--version-control={numbered,existing,simple}] [--dry-run] [--just-print] [--link-only] [--help] [--version] perlexpr [files]...
Rename renames the filenames supplied according to the rule specified as the first argument. The argument is a Perl expression which is expected to modify the $_ string for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input.
If a destination file is unwritable, the standard input is a tty, and the -f or --force option is not given, mv prompts the user for whether to overwrite the file. If the response does not begin with `y' or `Y', the file is skipped.
Make backups of files that are about to be removed.
Remove existing destination files and never prompt the user.
Prompt whether to overwrite each destination file that already exists. If the response does not begin with `y' or `Y', the file is skipped.
Print the name of each file before renaming it.
Do everything but the actual renaming, insted just print the name of each file that would be renamed. When used together with --verbose, also print names of backups.
Link files to the new names instead of renaming them. This will keep the original files.
Print a usage message on standard output and exit.
Print version information on standard output then exit successfully.
The suffix used for making simple backup files can be set with the SIMPLE_BACKUP_SUFFIX environment variable, which can be overridden by this option. If neither of those is given, the default is `~', as it is in Emacs.
The type of backups made can be set with the VERSION_CONTROL environment variable, which can be overridden by this option. If VERSION_CONTROL is not set and this option is not given, the default backup type is `existing'. The value of the VERSION_CONTROL environment variable and the argument to this option are like the GNU Emacs `version-control' variable; they also recognize synonyms that are more descriptive. The valid values are (unique abbreviations are accepted):
`t' or `numbered'
Always make numbered backups.
`nil' or `existing'
Make numbered backups of files that already have them, simple backups of the others.
`never' or `simple'
Always make simple backups.
To rename all files matching *.bak to strip the extension, you might say
rename 's/\e.bak$//' *.bak
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
More examples:
rename 's/\.flip$/.flop/' # rename *.flip to *.flop rename s/flip/flop/ # rename *flip* to *flop* rename 's/^s\.(.*)/$1.X/' # switch sccs filenames around rename 's/$/.orig/ */*.[ch]' # add .orig to source files in */ rename 'y/A-Z/a-z/' # lowercase all filenames in . rename 'y/A-Z/a-z/ if -B' # same, but just binaries! or even rename chop *~ # restore all ~ backup files
Two environment variables are used, SIMPLE_BACKUP_SUFFIX and VERSION_CONTROL. See "OPTIONS".
mv(1) and perl(1)
If you give an invalid Perl expression you'll get a syntax error.
Peder Stray <pederst@cpan.org>, original script from Larry Wall.
To install rename, copy and paste the appropriate command in to your terminal.
cpanm
cpanm rename
CPAN shell
perl -MCPAN -e shell install rename
For more information on module installation, please visit the detailed CPAN module installation guide.