[Techtalk] bash/perl script to rename files...

Michelle Murrain tech at murrain.net
Fri Oct 26 14:46:15 EST 2001

At 02:07 PM 10/26/2001, you wrote:
>I need a perl script that replaces spaces
>in a filename with underscores...
>I'm sure that this can be achieved, I just
>don't know how to do it.

#!/usr/bin/perl -w

use strict;

print "Filename:";
my $fname = <>;
chomp $fname;
my $ofname = $fname;
$ofname =~ s/\ /\\ /g;
$fname =~ s/\ /\_/g;

print "$ofname,$fname";
exec "mv $ofname $fname";


I'm sure there are more elegant scripts, but this works.


Michelle Murrain, Ph.D.
tech at murrain.net
http://www.murrain.net/public_key.html for pgp public key

More information about the Techtalk mailing list