Daniel B. Boorstein


pbr - Perl-based Batch Rename


pbr [-c] [-d dest_dir] [-D] [-i] [-l] [-p] [-t] [-v] [-w] PerlExpression Files ...

See below for description of the switches.


pbr is a perl-based batch renaming tool. Normally you wouldn't care about the implementation language of a tool, but in this case proper usage depends on your knowledge of perl.

The first argument to this program should be a perl expression that modifies $_. The remaining arguments are files that will potentially be renamed.

Each file name is temporarily placed in $_. The given expression is then evaled. Only if executing the expression results in the file name being changed, is the file renamed accordingly.

For example, if one of your input file names is foo.txt and your expression s/o/O/g, the renamed file will be fOO.txt.

On the command line, this would appear as:

   pbr s/o/O/g foo.txt

If your input file above was bar.txt, no change or rename would be made.



Perform a copy instead of a rename.

-d dest_dir

The destination for a renamed file will be the modified file's base name prepended with the given destination directory.


   pbr -vd new_dir/ s/o/O/g foo.txt
   move: foo.txt => new_dir/fOO.txt

Create directories if necessary.


Prompt the user for confirmation prior to performing the rename (interactive mode).


List available plugins and exit.


Treat the first argument as a plugin identifier rather than a perl expression. See PLUGINS section for details.


No renames will be performed (test mode). Implies -v.


Print diagnostic information concerning the renaming of files.


Store the whole path and file into $_. By default only the base name is put in $_. This allows your expression to see and modify the path.


   pbr -vw s/o/O/g foo/foo.txt
   move: foo/foo.txt => fOO/fOO.txt

Without the -w the above the expression would only operate on the base name of the file, resulting in the modified file name being 'foo/fOO.txt'.



Upper-case base name with substitution.

   pbr -v 's/(.+)/\U$1/' dir/abc123.txt
   move: dir/abc123.txt => dir/ABC123.TXT

Upper-case (ASCII-only) base name with transliteration.

   pbr -v tr/a-z/A-Z/ dir/abc123.txt
   move: dir/abc123.txt => dir/ABC123.TXT

Upper-case base name with assignment, move to specified directory.

   pbr -vd new_dir '$_ = uc' dir/abc123.txt
   move: dir/abc123.txt => new_dir/ABC123.TXT

Upper-case path and base name with assignment, create directory if necessary.

   pbr -vwD '$_ = uc' dir/abc123.txt
   move: dir/abc123.txt => DIR/ABC123.TXT

Replace directory separators with underscores.

   pbr -vw 'tr/\//_/d' dir/abc123.txt
   move: dir/abc123.txt => dir_abc123.txt


If you have complex renaming expressions that would benefit from being reusable, you can save them as plugins. When you pass the -p switch to pbr the first argument is treated as a plugin identifier rather than an expression to be evaled.

When loading the specified plugin, pbr first looks in the user's home directory for a .pbr/plugins/ directory. In that directory, it looks for a file named as $plugin_id . '.pl'.

If that file is not found it then searches the global plugin directory of /usr/share/pbr/plugins for a file of the same name.

Your plugin script should define a subroutine named &pbr_main. If it does not, pbr will die. Each file name you pass to pbr will be passed to the &pbr_main subroutine as the only argument. The return value of your &pbr_main subroutine will be the new file name to use in renaming.

For example, if you specify the date_name plugin, pbr first attempts to load the file; /home/username/.pbr/plugins/date_name.pl. If that is not found pbr attempts to load /usr/share/pbr/plugins/date_name.pl.

You can get a list of available plugins with the -l command. This will print them and then exit. If the first line of a plugin is a comment, the remainder of the line will be included in the list output as a comment about that particular plugin.

If no plugin is found pbr dies with a message.


o subroutines can be your friends, you need friends


Daniel B. Boorstein <danboo@cpan.org>

3 POD Errors

The following errors were encountered while parsing the POD:

Around line 283:

You forgot a '=back' before '=head1'

Around line 322:

You forgot a '=back' before '=head1'

Around line 358:

You forgot a '=back' before '=head1'