The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

brn - bulk rename - a fork of rename.

SYNOPSIS

brn [ { -v | -q } ... ] ] [ -n ] [ -f ] [ -D ] [ -C configpath ] [ -M perlmodule ] [ -p perlexpr [ -p perlexpr ... ] ] { [ -e ] perlexpr | -u preset } [ files ... ]

brn [ -C configpath ] { -L | --list } [ preset ] ...

brn [ -C configpath ] ... { -S | --save } preset

brn -V | --version

brn -? | --help

brn -R | --readme

brn -m | --man

DESCRIPTION

brn renames the filenames supplied according to the rule(s) given by the --expr (-e) option(s). If no such option is present then the first argument is taken to be the rule. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input.

For example, to rename all files matching *.bak to strip the extension, you might say

        brn 's/\.bak$//' *.bak

To translate uppercase names to lower, you'd use

        brn 'y/A-Z/a-z/' *

brn loads all Modules into a _USER package, and this is also where all expresions are evaluated. Note that the _USER package doesn't have 'strict' turned on, so variables do not need to be pre-declared. There are also a few predefined helper functions in its scope, to ease common rename tasks.

In void context, all of these helper functions output as if in scalar context by modifing their first parameter or $_ (if their parameter is unmodifiable). They will use $_ for their input data if called without. Thus, one can now uppercase all files in a directory just by saying

        brn 'uc' *

This can also be used in expression interpolation inside larger strings, so as to achieve more complex results. The command:

        brn 's/Show-(.*?).avi/Show - @{[ hc(spc($1)) ]}.avi/' *

Will extract a substring, perform space replacement, convert to highlight case, and re-insert the substring back into the name.

The full set of helper functions are:

slurp

slurp reads in an entire file given a filename or filehandle. In array context it returns individual chomped lines, while in scalar context it returns the entire file.

rd

rd reads entire directories and is the equivalent of slurp. In array context it returns an array containing all the entries in all the directories passed to it. In scalar context it returns all the directory names in a single string, separated by newlines.

spc($;$)

by default spc() takes a string and returns it with all dots ('.') and underscores ('_') converted to spaces. An optional second argument can provide a string of characters that overrides the list of characters to convert to spaces.

sc($)

sc() returns its input string converted to 'Sentence' case, meaning that the letter of each embedded sentence will be capitalized.

tc($)

tc() returns its input string converted to 'Title' case, meaning that the first letter of each word is uppercased.

hc($)

hc() returns its input string converted to 'Highlight' case, meaning that the first letter of each non-trivial word is uppercased.

OPTIONS

-v, --verbose

Verbose: increases the verbosity of brn. This option can appear multiple times, and each appearance increases brn's verbosity level by one. The option --quiet can be used to decrease verbosity. The following table lists the information presented at different verbosity levels. The default verbosity is 1.

    -1 Very Quiet No Text Output at All
    0 Quiet Only Display Errors
    1 Normal Display Errors and Warnings
    2 Verbose List the Files being Processed.

Note that currently not all text is surpressed at level -1.

-q, --quiet

Quiet: decreases the verbosity level of brn by 1. See --verbose for a discussion of verbosity levels.

-n, --nop

No Operation (NOP): show what files would have been renamed.

-f, --force

Force: overwrite existing files.

-D, --debug

Debug: Turn on internal debugging shims. Intended for developers only.

-e, --expr

Expression: this option holds a rename expression to be used to rename files. Multiple instances of this flag may appear on the command line, and they are executed in order, for each file specified.

If no occurance of this flag appears on the command line, then the first argument will be taken as a rename expression and subsequent arguments will be taken as file names.

If this flag does appear on the command line, then all arguments are assumed to be file names.

-M module[=foo,bar]

Load the listed modules at the start of the program. If the optional extra parameters are added, then they will be used to import the listed functions. Multiple instances can appear on the command line, and they will be loaded in the order given.

-p perlexpr, --preamble=perlexpr

Preamble: execute the expression once, before looping over the files to rename, this can be useful to load data files or do other setup before complex rename procedures. Multiple preambles can be given, and they will be executed in order.

-u | --use preset

Use preset: Rather than specifying a complex operation on the command line, you can also save a set of command line options in a config file, and use them by using the 'use' option. By default the config file is stored in ${HOME}/.config/rn.conf but this can be changed with the --config (-c) command. Multiple use options can be specified, and their operations will be executed in turn.

-S | --save preset

Save preset: Rather than executing the contents of the current command line, the options will be stored in the rn config file under the given preset name.

-L | --list preset

List preset: Rather than performing a rename operation, just list the command line options stored under the given preset name. Multiple --list options can be given, to see multiple presets.

-C | --config configpath

Normally, all stored presets are assumed to be in the default location, which is ${HOME}/.config/rn.conf, but this can be changed on a preset-by-preset basis with the --config option, which allows you to specify the full pathname of another config file.

If a preset itself references other presets then they will be looked up either in the last specified config file, which will be the one specified in that preset (if any).

-V | --version

Version: display the current version of this program.

-?, --help

Help: Display this documentation.

-m, --man

Manual: Display a full man page.

EXIT CODES

brn returns an exit code indicating the success or failure of the requested operation. 0 always indicates a success. A return code less than 16 indicates success in an auxiliary function of brn (such as successfully return its version.) Starting at 16, the error codes indicate various fatal errors.

    0 None No Error
    1 Help Help was requested
    2 Docs Readme or manual was requested
    3 Info Other information was requested
    16 General Unknown Error
    17 NoSuchFile File Not Found
    18 BadConfigFile Configuration File Error
    19 BadPreset No Such Preset
    20 NotImplemented This Feature is Currently Not Implemented

ENVIRONMENT

The 'HOME' environment variable is used to determine the default location of the rn.conf file.

AUTHOR

 Original Author: Larry Wall
 Second Author:   Robin Barker
 Current Author:  Stirling Westrup

SEE ALSO

mv(1), perl(1), rename(1), prename(1), File::rename(3pm), App::perlmv(3pm)

DIAGNOSTICS

If you give an invalid Perl expression you'll get a syntax error.

BUGS

There are probably innumerable bugs in this code as it is still in alpha state. Among the known problems are the possibly incorrect chaining of -u options, and the failure to always maintain the order of mixed -e and -u options.

In addition there are many stubs for features that do not yet work fully (if at all) and the documentation is slightly behind the work.

HISTORY

The original rename did not check for the existence of target filenames, so had to be used with care. I hope I've fixed that (Robin Barker).

The original rename seemed to me to be lacking a number of useful features, and as its last update had been back in 1998, I (Stirling Westrup) decided to fork a version to work on.