NAME

rename.pl - mangle filenames using perl expressions


SYNOPSIS

Append .old to a bunch of files:

  $ rename.pl 's/$/.old/' *

Fix the case on all .C files to lower, doing a preview of changes only:

  $ rename.pl -p 'tr/A-Z/a-z/' *.C


DESCRIPTION

A file renamer that uses user-supplied perl expressions to rename files. Optionally, the copy() or move() routines from File::Copy may be used instead of the builtin rename() function.

A preview mode is also available, to allow testing of expressions before any changes are allowed to go to disk.


USAGE

  $ rename.pl [options] expression [file1 file2 .. fileN]

See OPTIONS for details on the command line switches supported.

If no files are mentioned on the command line, the script will attempt to read them from STDIN, allowing for easy interoperation with various shell utilities. In this case, fix .htm files to .html:

  $ find . ! -type d -name "*.htm" | rename.pl '$_ .= "l"'


OPTIONS

This script currently supports the following command line switches:

-h / -?
Prints a brief usage note about the script.

-p
Enable preview mode, no changes will be made to disk.

-v
Be verbose about the whole process.

-c
Copy files instead of renaming them, using copy() from File::Copy.

-m
Move files instead of renaming them. Uses move() from File::Copy, which may not be available in older versions of File::Copy.

Since rename() cannot be used across filesystem boundaries, and may not be available on all systems, move() may be a better option in some circumstances.

-i
Interactive mode: prompts for confirmation.

-f
Force mode. Does not prompt to replace existing files.


EXAMPLES

Remove upper case from a bunch of files:

  $ rename.pl '$_ = lc' *

Dealing with deep directories full of files to be changed can be tricky, especially if the pattern in question is renaming directories, which will throw off the rename of deeper files.

The solution is to first change all the directories, then go after the files. For example, to swap out ``bad'' characters with _ in a deep file tree:

    $ find . -type d -exec rename.pl 's/[^A-Za-z0-9,.\/_-]/_/g' {} \;
    $ find . -exec rename.pl 's/[^A-Za-z0-9,.\/_-]/_/g' {} \;


BUGS

Reporting Bugs

Newer versions of this script may be available from:

http://sial.org/code/perl/

If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.

Known Issues

Bugs are left as an exercise to the expression writer. :)


SEE ALSO

File::Copy, perl(1)


AUTHOR

Jeremy Mates, http://sial.org/contact/


COPYRIGHT

Copyright (c) 2000-2002, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


HISTORY

This is a hacked up version of Larry Wall's original rename script distributed with perl under the eg directory, improved by Daniel V. Klien (copy option, interactive mode), and then polished into this form by Jeremy Mates (preview mode, comments in source, move support).


VERSION

$Id: rename.pl,v 2.4 2003/01/13 05:28:42 jmates Exp $