perlmv - Rename files using Perl code


NAME

perlmv - Rename files using Perl code

Back to Top


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

Back to Top


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 the App::perlmv::scriptlets manpage, or in %scriptlets in the App::perlmv::scriptlets::std manpage.

Back to Top


OPTIONS

 -c  (--compile) Only test compile code, do not run it on the arguments
 -e <CODE> (--execute) Specify code to rename file (\$_), e.g.
     's/\.old\$/\.bak/'
 -D <NAME> (--delete) Delete scriptlet
 -d  (--dry-run) Dry-run (implies -v)
 -f  (--files) Only process files, do not process directories
 -h  (--help) Show this help
 -l  (--list) list all scriptlets
 -M <MODE> (--mode) Specify mode, default is 'rename' (or 'r'). Use
     'copy' or 'c' to copy instead of rename, 'symlink' or 's' to create
     a symbolic link, and 'link' or 'l' to create a (hard) link.
 -o  (--overwrite) Overwrite (by default, ".1", ".2", and so on will be
     appended to avoid overwriting existing files)
 -p  (--parents) Create intermediate directories
 -R  (--recursive) Recursive
 -r  (--reverse) reverse order of processing (by default order is
     asciibetically)
 -S  (--no-symlinks) Do not process symlinks
 -s <NAME> (--show) Show source code for scriptlet
 -V  (--version) Print version and exit
 -v  (--verbose) Verbose
 -w <NAME> (--write) Write code specified in -e as scriptlet

Back to Top


FAQ

Why should I use perlmv? There is prename (File::Rename) 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.

And there is also pmv (File::PerlMove)!

Okay, you got me. I didn't do my homework. The "rename files using Perl code/expression" is pretty obvious and has surely come up on other CPAN authors' minds. To be honest, this is a script which I wrote years ago (at least in 2003, or earlier) and have been using for years, personally. Admittedly I uploaded this script to CPAN without careful checking of existing solutions on CPAN. But then, lots of other CPAN modules are also overlapping in functionality with one another.

Anyway, I plan to improve perlmv as I see fit, mainly for my own needs. I plan to borrow some features from prename/pmv, and welcome them borrowing features from perlmv. I welcome patches. And I am willing to submit patches to prename/pmv after some discussions with the respective authors. And lastly, I am also open to the idea of merging perlmv to either pername/pmv, if I can get all the features I love in perlmv into those projects.

Back to Top


BUGS/TODOS

Back to Top


SEE ALSO

prename (the File::Rename manpage)

pm (the File::PerlMove manpage)

Back to Top

 perlmv - Rename files using Perl code