|| Ever get that pesky error 'Arg list too long' when you're trying to rm a bunch of files? Yeah, it's a limitation of the shell, not rm. But, it's an annoyance nonetheless. So, this morning I whipped this little baby up in about an hour.
Feedback is VERY much appreciated!
## Written by Jim Conner 24 Jan 2006
## <snafuxnj ->at<- yeah-hoo (dot) com>
## Purpose: When the command `rm *` fails due
## to shell limitations for glob operations
## aka * wildcard equals too many arguments for
## substitution to work properly then you can
## use this little script to remove everything
## in the directory specified. It DOES NOT
## work recursively. At least not yet.
my $rev = '0.1';
my $plProgName = basename($0);
GetOptions('directory=s' => \@DIRS ,
'help' => \&HELP_MESSAGE ,
'version' => \&VERSION_MESSAGE,
if ( scalar(@DIRS) > 0 )
for my $dir ( @DIRS )
if ( -d $dir )
if ( chdir($dir) )
unless ( my $num_unlinked = unlink(<*>) )
print STDERR 'Unable to remove all files in '.$dir
print STDERR ': '.$!,"\n";
print $num_unlinked .' files were removed.',"\n";
print STDERR 'Unable to chdir to '.$dir.': '.$!,"\n";
print STDERR $dir,' is not a valid directory or is unreada
Usage: $plProgName <--directory|-d <directory>> --directory|-d <di
You must specify -d argument.
NOTE: Once you successfully run this program for a directory
the files within that directory will ALL be removed.
This program DOES NOT recursively remove files and it
will NOT remove directories.
bigrm - Remove all files non-recursively in a given set of directories
Ever get the error from the rm command: 'Arg list too long'? This is
problem with the shell and not rm. It happens when you supply the '*'
glob wildcard to the command rm. So, I wrote this little program to
help with this little annoyance. This nifty little guy will simply re
every non-directory file in a directory(ies) specified on the command
It will NOT remove directories in the directory(ies) nor will it recur
work in the directory(ies) specified.
That functionality can be written into this program but its not what I
needed and I don't have time to write it in. I whipped this little gu
out in about 1 hour (had to read up on some Getopts::Long stuff).
bigrm <--directory|-d <directory>> --directory|-d <directory>...
=head1 SEE ALSO
Jim Conner <snafuxnj ->at<- yeah-hoo (dot) com>