You don't make it clear whether all these files are in a single directory, or in a directory heirarchy. I'm going to assume the former. Most shell commands and much perl code will appear to hang forever, since it will attempt to read the entire directory listing into memory, then sort it, before doing anything else. What you need (in general terms)
is the following perl code, which must be run from the directory in question:
#!/usr/bin/perl
use warnings;
use strict;
opendir my $dir, '.' or die "opendir .: $!\n";
my $file;
my $count = 0;
while (defined($file = readdir($dir))) {
# give yourself some progression feedback
$count++;
print "file $count ...\n" unless $count % 1000;
# skip all files not begining with b
next unless $file =~ /^b/;
# if you've created directories, may need to skip them;
# this will slow things down, so don't do so unless necessary
next unless -f $file;
# do something with the file
rename $file, "b/$file" or die "rename $file b/$file: $!\n";
}
This example deals with directory entries at the most efficient and lowest level. In this case, it just moves all files starting with "b" into the subdirectory b/.
Obviously it needs adapting to your particular needs. For example, the rename could become
system "gzip", $file;
Dave.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|