NAME

perlmv - Rename files using Perl code

VERSION

0.27

SYNOPSIS

Usage:

perlmv -h

perlmv [options] <scriptlet> <file...>
perlmv [options] -e <code> <file...>

perlmv -e <code> -w <name>
perlmv -l
perlmv -s <name>
perlmv -d <name>

Usage examples

$ ls
A.txt B1 c2.txt D3.pl D4.pl

Rename files with prewritten scriptlet (ls) and show (-v) each file as it is being renamed.

$ perlmv -v lc *.txt
`A.txt` -> `a.txt`

Specify script in command line (-e) but do not actually rename files (-d, dry-run mode):

$ perlmv -de 's/\d+//g' *
`B1` -> `B`
`c2.txt` -> `c.txt`
`D3.pl` -> `D.pl`
`D4.pl` -> `D.pl.1`

Really rename the files this time:

$ perlmv -e 's/\d+//g' *

Save Perl code as scriptlet (in ~/.perlmv/scriptlets/):

$ perlmv -e 's/\d+//g' -w remove-digits

List all scriptlets (add -v to also show their contents):

$ perlmv -l
lc
uc
remove-digits

Show source code of scriptlet:

$ perlmv -s remove-digits
s/\d+//g

Remove scriptlet:

$ perlmv -D remove-digits

DESCRIPTION

Perlmv lets you rename files using Perl code. All the Perl code needs to do is modify the filename in $_ and perlmv will do the rest (actual renaming, recursive renaming, handling filename conflicts, dry-run mode, etc.).

Perl code will first be run (eval-ed) once at the beginning for testing, with -TEST as the filename in $_ (and $TESTING will be defined). Perl code is not run under strict/warnings. Perl code is run under App::perlmv::code namespace.

Perl code can be specified directly from the command line (using -e), or by name in ~/.perlmv/scriptlets/NAME, or in /usr/share/perlmv/scriptlets/, or in %scriptlets in App::perlmv::scriptlets, or in %scriptlets in App::perlmv::scriptlets::std.

OPTIONS

-c  Only test compile code, do not run it on the arguments
-e <CODE> Specify code to rename file (\$_), e.g. 's/\.old\$/\.bak/'
-d  Dry-run (implies -v)
-f  Only process files, do not process directories
-h  Show this help
-o  Overwrite (by default, ".1", ".2", and so on will be appended to
    avoid overwriting existing files)
-r  Recursive
-S  Do not process symlinks
-V  Print version and exit
-v  Verbose

-l  list all scriptlets
-s <NAME> Show source code for scriptlet
-w <NAME> Write code specified in -e as scriptlet
-D <NAME> Delete scriptlet

FAQ

Why should I use perlmv? There is prename already?

Yes, there is a very similar script called prename (also accessible via rename in Debian) which comes with Perl. This script reinvents prename and offers more features, e.g.: automatic renaming in case of conflicts, recursive mode, and saving and loading scriptlets.

BUGS/TODOS

  • Patches for Windows welcome.

  • Scriptlet should be able to receive arguments.

SEE ALSO

prename.