deleting a list of files

By ET

Suppose you have a dirctory of thousands of files, you need to delete some of them.  If the filenames are sufficiently friendly, you can do it easily with a command line.

For example:

rm *.old or rm old*.zip

But, consider this case: files are named with the date they were  generated and there are two types of names

  1. those look like file20051002.zip, and
  2. those look like filemini20051002.zip

Is there a way to only delete the files with "mini" within the filename?

It is not hard to get the list of these files, in linux, it is simply:

ls | grep mini >listfile

Searching in google, I found a linux command called "fastrm" that does delete all files in the list "listflie", but I don’t have it in my Redhat Enterprise Server 3.

So I wrote the following script to do that:

 open (FILE, "< listfile");

while (<FILE>){
        $file=($_);
        chomp($file);
        unlink($file);
}
close FILE;

 Now it is very easy to delete files in the list:

 the command is : ls |grep mini>listfile; perl rmlist.pl;

Leave a Reply


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2020. All rights reserved.
All trademarks property of their owners.