[ale] Stupid Shell Trick
Mike Fletcher
fletch at phydeaux.org
Thu Feb 11 22:24:44 EST 1999
>>>>> "Todd" == Todd Graham Lewis <tlewis at mindspring.net> writes:
Todd> On Wed, 10 Feb 1999, Wandered Inn wrote:
>> for f in $(find . -name '*\;*' -print); do mv -i "$f"
>> "${f%;*}"; done
Todd> This consumes an amount of memory proportional to the size
Todd> of the directory tree. To do it in constant space, do the
Todd> following:
Todd> # find . -name '*\;*' -print | while read f
while> do mv -i "$f" "${f%;*}" done
TMTOWTDI. :)
Put the following into a script (maybe called `unversionize')
and chmod it executable:
#/usr/bin/perl
use File::Find;
die "usage: $0 dir [dir . . .]" unless scalar @ARGV;
find( sub { /^([^;]+);\d+$/ && rename $_ => $1 }, @ARGV );
Or if you just need to use it once or twice, the command line
version would be:
perl -MFile::Find -e 'find(sub{/^([^;]+);\d+$/&&rename $_=>$1}, at ARGV)' dir
Keep in mind that you can use any perl code to decide what to
do as you walk the directory tree (e.g. you could only unversion files
ending in `.c' or `.h' that have been modified within the last week
that are over 2k in length and the owner is . . . ). For more info,
`perldoc File::Find' or `man File::Find' depending on your MANPATH
settings.
--
Fletch | __`'/|
fletch at phydeaux.org | "I drank what?" -- Socrates \ o.O'
678 443-6239(w) | =(___)=
| U
More information about the Ale
mailing list