Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  PMV (1)

.ds Aq ’


pmv - rename files according to perl code



<B>pmvB> [-vqdmMrh] [-b startcode] [-e endcode] [--] ’perl code’ <files...>


pmv allows you to manipulate filenames based on arbitrary perl code. Think of it like <B>perl -peB> but operating on the filename instead of the file contents. It is useful for renaming large numbers of files according to arbitrary criteria.

In the code you write, <B>B>$_<B>B> is set to the current filename, and you should change <B>B>$_<B>B> to what you want the new filename to be. This enables you to write quick oneliners like:

        pmv s/$/.bak/; *

If you want more control, there are three variables defined:
<B>B>$file<B>B> Same as <B>B>$_<B>B>, the filename passed in on the command line.
<B>B>$path<B>B> The full pathname, without the filename.
<B>B>$name<B>B> The filename, without any path components.
You can alter any of these variables to get the same effect as altering <B>B>$_<B>B>. Which to use is determined as follows:
<B>1:B> If <B>B>$file<B>B> has been altered, that is used.
<B>2:B> If <B>B>$path<B>B> or <B>B>$name<B>B> has been altered, they are joined together then used.
<B>3:B> Otherwise, <B>B>$_<B>B> is used.
The file contains useful example bourne shell functions that use pmv. This is available in the source distribution, and will probably be installed under /usr/share/doc/mp3-archive-tools/.

This file can be sourced by (using <B>sourceB> or <B>.B>) or included in one of your startup files (eg /etc/profile or $HOME/.bash_profile for bash(1) users.


<B>-vB> Verbose.
<B>-qB> Quiet (no output). This is the default.
<B>-dB> Dry run. Shows how it would rename files without actually doing it.
<B>-bB> startcode Specifies perl code to run once before processing files. Useful for useing modules and doing one-time initialisation.
<B>-eB> endcode Specifies perl code to run once after processing files. Useful for summarising data gathered from filenames.
<B>-mB> If the pathname has been altered, create any necessary directories.
<B>-rB> If a file is moved out of a directory, remove any empty directories.
<B>-MB> Same as <B>-m -rB>.
<B>-hB> Show a brief usage summary.
<B>--B> End of options.


If you have sourced (see above>, the following functions are available:
<B>pmv-stdswapB> Swaps round fields in filenames delimited by - .
<B>pmv-space2_B> converts all spaces in filename to underscores.
<B>pmv-_2spaceB> Converts all underscores in filename to spaces.
<B>pmv-fixcapsB> Crude attempt at capitalising filenames.
<B>pmv-fixcaseB> Much better attempt at capitalising filenames. This requires the <B>Text::AutoformatB> module from CPAN (
<B>pmv-numberB> Numbers filenames sequentially.
<B>pmv-deepenB> Converts directoriess from artist - album to artist/album
<B>pmv-flattenB> Converts directoriess from artist/album to artist - album
<B>pmv-datestampB> Insert a datestamp in the form YYYYMMDD at the start of the filename. See below for more details.


<B>Convert all whitespace in all mp3 filenames to underscoresB>

 pmv s/\s/_/g; *.mp3

<B>Convert the spelling of Color to Colour in all filenamesB>

 pmv s/Color/Colour/gi; *

<B>Swap round fields in mp3 filenamesB>

 pmv $name=~s/(.*) - (.*) - (.*) - (.*)(\..*)/$3 - $1 - $2 - $4$5/; *.mp3

This would convert eg:

 Primal Scream - Screamadelica - 04 - Higher Than The Sun.mp3


 04 - Primal Scream - Screamadelica - Higher Than The Sun.mp3

<B>Crudely capitalise every word in all filenamesB>

 pmv  $name=join(" ",map({ucfirst(lc($_));} split(/\s+/,$name))); *

See <B>pmv-fixcaseB> in for a better way to capitalise filenames.

<B>Add a datestamp to the start of all filenamesB>

 pmv -b $d=`date +%Y%d%m`;chomp($d); $name = "$d.$name"; *

This adds a datestamp in the form YYYYMMDD (eg 20031214) to the start of a filename. Files with datestamps in this form will sort in date order, which is useful for (e.g.) logfiles.

The <B>-bB> code to get the date is run only once, before the files are processed.

If you wanted to make this into a shell function, callable by typing pmv-datestamp files, you would insert the following into your startup files:

 function pmv-datestamp
     pmv -b $d=`date +%Y%d%m`;chomp($d); $name = "$d.$name"; "$@"


Rather similar (I recently discovered) to rename(1), which ships with perl. However, pmv provides several features that rename does not have, and the pmv- shell functions in are useful, so I decided to add it to the mp3-archive-tools(1) package anyway.


perl(1), mp3-archive-tools(1), mp3lint(1)


Ian Beckwith <>


pmv is part of the mp3-archive-tools package.

The latest version can be found at:


Copyright 2003 Ian Beckwith <>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Search for    or go to Top of page |  Section 1 |  Main Index

perl v5.20.3 PMV (1) 2003-12-12

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.