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
Only if executing the expression results in the file name being changed,
is the file renamed accordingly.
if one of your input file names is
foo.txt and your expression
the renamed file will be
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.
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
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
-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
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
pbr first attempts to load the file;
/home/username/.pbr/plugins/date_name.pl. If that is not found
pbr attempts to load
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.
Daniel B. Boorstein <firstname.lastname@example.org>