rename1p
Rename multiple files using perl expressions
Usage
rename [-bcfgilnv]
[-B
prefix]
[-C
command]
[-S
suffix]
[-V
method]
[-Y
prefix]
[-z
suffix]
[--backup]
[--command=command]
[--copy]
[--basename-prefix=prefix]
[--dry-run]
[--force]
[--help]
[--no-stdin]
[--interactive]
[--just-print]
[--link-only]
[--prefix=prefix]
[--suffix=suffix]
[--verbose]
[--version-control=method]
[--version]
perlexpr
[files] ...
Overview
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 (unless --no-stdin is supplied on the command line).
If a destination file is unwritable, the standard input is a tty, and the -f or --force option is not given, rename prompts the user for whether to overwrite the file. If the response does not begin with `y' or `Y', the file is skipped.
Options
-
-b, --backup -
Make backup files. That is, when about to overwrite a file, rename the original instead of removing it. See the
-Vor--version-controloption fo details about how backup file names are determined.
-
-B prefix, --prefix=prefix -
Use the
simplemethod to determine backup file names (see the-Vmethod or--version-control=method option), and prepend prefix to a file name when generating its backup file name.
-
-c, --copy -
Copy files to the new names instead of renaming them. This will keep the original files.
-
-C command, --cmd command, --command command -
Use command to process files instead of rename. command can contain two instances of {}, the first will be replaced with the original filename, the second with the new. Without any {}'s, the old and new filename will be appended to the command.
-
-f, --force -
Remove existing destination files and never prompt the user.
-
-g, --git -
Shortcut for --command "git mv".
-
-h, --help -
Print a summary of options and exit.
-
--no-stdin -
Disable reading of filenames from STDIN. Us it when your shell has nullglob enabled to make sure rename doesn't wait for input.
-
-i, --interactive -
Prompt whether to overwrite each destination file that already exists. If the response does not begin with `y' or `Y', the file is skipped.
-
-l, --link-only -
Link files to the new names instead of renaming them. This will keep the original files.
-
-n, --just-print, --dry-run -
Do everything but the actual renaming, instead just print the name of each file that would be renamed. When used together with
--verbose, also print names of backups (which may or may not be correct depending on previous renaming).
-
-v, --verbose -
Print the name of each file before renaming it.
-
-V method, --version-control=method -
Use method to determine backup file names. The method can also be given by the
RENAME_VERSION_CONTROL(or if that's not set, theVERSION_CONTROL) environment variable, which is overridden by this option. This option does not affect whether backup files are made; it affects only the name of any backup files that are made.The value of method is like the GNU Emacs `version-control' variable;
renamealso recognize synonyms that are more descriptive. The valid values are (unique abbreviations are accepted):existingornil-
Make numbered backups of files that already have them, otherwise simple backups. This is the default.
numberedort-
Make numbered backups. The numbered backup file name for F is F.~N~ where N is the version number.
simpleornever-
Make simple backups. The
-Bor--prefix,-Yor--basename-prefix, and-zor--suffixoptions specify the simple backup file name. If none of these options are given, then a simple backup suffix is used, either the value ofSIMPLE_BACKUP_SUFFIXenvironment variable if set, or ~ otherwise.
-
--version -
Print version information on standard output then exit successfully.
-
-Y prefix, --basename-prefix=prefix -
Use the
simplemethod to determine backup file names (see the-Vmethod or--version-control=method option), and prefix prefix to the basename of a file name when generating its backup file name. For example, with -Y .del/ the simple backup file name fora/b/fooisa/b/.del/foo.
-
-z suffix, -S suffix, --suffix=suffix -
Use the
simplemethod to determine backup file names (see the-Vmethod or--version-control=method option), and append suffix to a file name when generating its backup file name.
-
--shell-completion=shell, --shellcompletion=shell -
Generate shell code for parameter completion for either
bashorzsh.
Examples
To rename all files matching *.bak to strip the extension, you might say
rename 's/\.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 *.floprename s/flip/flop/ * # rename *flip* to *flop*rename 's/^s\.(.*)/$1.X/' * # switch sccs filenames aroundrename '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 evenrename chop *~ # restore all ~ backup files
Use --git when working within a GIT repo:
# rename _-separated filenames to camel-case, using git mvrename --git 's/([a-z]+)_/\u\L$1/g' *.c# or just renaming all the *.yml files to *.yamlrename -g 's/\.yml$/.yaml/ *.yml
With the --command parameter you can make rename do other interesing stuff like:
# make thumbnails in PNG format of all JPEG filerename 's/\.jpg/-thumb.png/' -C 'convert {} -resize 120x120 {}' *.jpg
Environment
Two environment variables are used, SIMPLE_BACKUP_SUFFIX and VERSION_CONTROL. See "OPTIONS".
Diagnostics
If you give an invalid Perl expression you'll get a syntax error.