Warning: include_once(/home/nullvoid/blog.mikezhang.com/wp-content/plugins/wordpress-support/wordpress-support.php): failed to open stream: Permission denied in /home/nullvoid/blog.mikezhang.com/wp-settings.php on line 216

Warning: include_once(): Failed opening '/home/nullvoid/blog.mikezhang.com/wp-content/plugins/wordpress-support/wordpress-support.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/nullvoid/blog.mikezhang.com/wp-settings.php on line 216
NullVoid » deleting a list of files NullVoid » Blog Archive » deleting a list of files


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.