| 
 
     
- UID
 - 1 
 - 威望
 - 1240 点 
 - 金钱
 - 24019 金币 
 - 点卡
 - 317 点 
 
  | 
1#
 
发表于 2005-8-25 19:12
 |  只看该作者
 
 
 
 删除Unix上目录文件过多问题
作者:小歪歪 
email: annysun@163.net 
日期:9/3/2001 3:03:59 PM 
    大家有没有碰到过unix上,一个目录文件太多,无法删除的现象,我为大家写了个perl的程序删除! 
cat > del.pl- #!/usr/bin/perl
 - $file1=$ARGV[0];
 - @tests=(1,2,3,4,5,6,7,8,9,';A';,';B';,';C';,';D';,';E';,';F';,';G';,';H';,';I';,';G';,';K';,';L';,';M';,';N';,';O';,';P';,';Q';,';R';,';S';,';T';,';U';,';V';,';W';,';X';,';Y';,';Z';);
 - foreach  $test(@tests) {
 - $file=$file1.$test;
 - @chars=(0,1,2,3,4,5,6,7,8,9,';A';,';B';,';C';,';D';);
 - foreach $char(@chars) {
 - `rm $file$char*`;
 - }
 - `rm $file*`;
 - }
 - `rm $file1*`;
 
  复制代码 ——————以下内容由Cnangel在2005年08月25日 07:15pm时添加——————— 
 
个人感觉是一种比较差的程序! 
请看下面两种语言写的程序: 
PERL:- #!/usr/bin/perl
 - ################################################################################
 - #               NT/UNIX/LINUX/BSD各系统死锁文件超级删除工具
 - #
 - #                         荣誉出品:94Cool.Net
 - #
 - #                                                                   作者:BigJim
 - #                                                                     2002/09/25
 - ################################################################################
 - #读取提交参数部分
 - $user="cnangel";  #可以写一个管理会员的sub程序,实现多用户操作
 - $password="自己的密码";
 - if ($ENV{';REQUEST_METHOD';} eq "POST") {
 -   read(STDIN, $buffer, $ENV{';CONTENT_LENGTH';});
 - } 
 - else {
 -   $buffer = $ENV{';QUERY_STRING';};
 - }
 - @pairs = split(/&/, $buffer);
 - foreach $pair (@pairs) {
 -    ($name, $value) = split(/=/, $pair);
 -    $value =~ tr/+/ /;
 -    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 -    $value =~ s/<!--(.|\n)*-->//g;
 -    $value =~ s/\t//g;
 -    $value =~ s/>/>/g;
 -    $value =~ s/</</g;
 -    $FORM{$name} = $value;
 - }
 - $action     = $FORM{';action';};
 - $u = $FORM{';u';};
 - $pass = $FORM{';pass';};
 - $u = &clean($u);
 - $pass = &clean($pass);
 - if((!$action)||($action eq "login")){&godown;}
 - if($action eq "del"){&main;}
 - sub godown{
 - if(($u eq $user)&&($pass eq $password)) {
 - &main;
 - }else{
 - &login;
 - }
 - }
 - sub main{
 - $|=1;
 - if ($ENV{';REQUEST_METHOD';} eq "POST")
 - {
 - read(STDIN, $buffer, $ENV{';CONTENT_LENGTH';});
 - }
 - else
 - {
 - $buffer = $ENV{';QUERY_STRING';};
 - }
 - @pairs = split(/&/, $buffer);
 - foreach (@pairs)
 - {
 - ($name, $value) = split(/=/, $_);
 - $value =~ tr/+/ /;
 - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 - $value =~ s/<!--(.|\n)*-->//g;
 - $value =~ s/\t/--/g;
 - $value =~ s/>/>/g;
 - $value =~ s/</</g;
 - $FORM{$name} = $value;
 - }
 - print "Content-Type: text/html\n\n";#输出HTTP头
 - #如果提交了删除对象,则删除对象,如果没有,则显示主程序界面
 - if (defined($FORM{';deltarget';}))
 - {
 - my $deltarget = $FORM{';deltarget';};
 - $deltarget =~ s/[\/\\]*$//o;
 - $deltarget =~ s/\\/\//g;
 - if (&del($deltarget))#删除成功
 - {
 - print qq~
 - <html><title>删除成功!</title>
 - <head><meta http-equiv="Content-Type" Content="text/html; charset=gb2312"></head>
 - <body><p>删除目标文件(夹)成功!</p><p><a href="javascript:history.go(-1);">返回上一页</a></p></body>
 - </html>~;
 - }
 - else#删除失败
 - {
 - print qq~
 - <html><title>删除失败!</title>
 - <head><meta http-equiv="Content-Type" Content="text/html; charset=gb2312"></head>
 - <body><p>删除目标文件(夹)失败!</p><p><font color=red>可能原因:目标文件(夹)不存在或者对于目标文件夹或者里面的一些文件没有权限删除!</font></p><p><a href="javascript:history.go(-1);">返回上一页</a></p></body>
 - </html>~;
 - }
 - }
 - else
 - {
 - &display;
 - }
 - exit;
 - }
 - sub getmypath#获取程序所在的绝对路径$mydir和程序名称$thisprog的函数
 - {
 - if ($ENV{';SCRIPT_FILENAME';})
 - {
 - $mydir = substr($ENV{';SCRIPT_FILENAME';}, 0, rindex($ENV{';SCRIPT_FILENAME';}, "/"));
 - }
 - else
 - {
 - $mydir = substr($ENV{';PATH_TRANSLATED';}, 0, rindex($ENV{';PATH_TRANSLATED';}, "\\"));
 - $mydir=~ s/\\/\//g;
 - }
 - $thisprog = substr($ENV{';SCRIPT_NAME';}, rindex($ENV{';SCRIPT_NAME';}, "/") + 1, length($ENV{';SCRIPT_NAME';}));
 - return;
 - }
 - sub del#删除一个目录或者是文件的函数,调用参数为文件或者是目录名
 - {
 - my $deltarget = shift;
 - return 1 if (unlink($deltarget));
 - return 0 unless (opendir(DIRS, $deltarget));
 - my @dirlist = readdir(DIRS);
 - closedir(DIRS);
 - my $delstatus = 1;
 - foreach (@dirlist)
 - {
 - next if ($_ eq "." || $_ eq "..");
 - $delstatus = 0 unless (&del($deltarget . "/" . $_));
 - }
 - return 0 unless($delstatus);
 - return 0 unless(rmdir($deltarget));
 - return 1;
 - }
 - sub display#显示本死锁文件删除程序的主界面
 - {
 - &getmypath;
 - print qq~<!--Powered By 94Cool.Net-->
 - <html><title>NT/UNIX/LINUX/BSD各系统死锁文件超级删除工具</title>
 - <head>
 - <meta http-equiv="Content-Type" Content="text/html; charset=gb2312">
 - <style type="text/css">
 - .title{font-family: 宋体; font-size: 15px; line-height: 130%; color: #9fc607; filter: glow(color=#333333, strength=1); position: relative; width: 100%}
 - .cont1{font-family: 宋体; font-size: 12px; line-height: 130%; color: #ff0000}
 - .cont2{font-family: 宋体; font-size: 12px; line-height: 130%; color: #000000}
 - .copy{font-family: 黑体; font-size: 15px; line-height: 130%}
 - </style>
 - <script language="JavaScript">
 - function go1()
 - {
 - if (window.event.keyCode == 13)
 - return confirm(';你确认要将服务器上的 "'; + document.FORM.deltarget.value + ';" 目录完全删除么?';);
 - else
 - return true;
 - }
 - function go2()
 - {
 - return confirm(';你确认要将服务器上的 "'; + document.FORM.deltarget.value + ';" 目录完全删除么?';);
 - }
 - </script>
 - </head>
 - <body>
 - <p align=center class=title>NT/UNIX/LINUX/BSD各系统死锁文件超级删除工具</p>
 - <form name=FORM action=$thisprog method=POST>
 - <input type=hidden name=action value=del>
 - <p class=cont1>需要删除的目录或者文件的绝对路径:</p>
 - <p class=cont1><input name=deltarget type=text size=64 OnKeyDown="return go1();">  <input type=submit value=删除(请慎用) OnClick="return go2();"></p>
 - </form>
 - <p class=cont1>请在上面填写你要删除的目录在主机上的绝对路径,如果是UNIX/LINUX/BSD主机直接填相对路径也可以!请小心使用,删除后,文件夹和文件夹中的文件将全数被删除掉!如果目录下面有深层路径也不必担心要手动一步步来做,程序会帮你全部删除:)</p>
 - <p class=cont1>NT例子:f:/www/cgi-bin/bbs/data</p>
 - <p class=cont1>UNIX例子:user/home/cgi-bin/bbs/data</p>
 - <p class=cont1>UNIX例子(相对路径):bbs/data</p>
 - <p class=cont2>当前CGI程序所在的绝对路径:$mydir</p>
 - <p align=center class=copy>©荣誉出品:<b><font color=5599ff>94Cool</font>.<font color=ff9955>Net</font></b></p>
 - </body>
 - </html>
 - ~;
 - return;
 - }
 - sub login{
 - print "Content-Type: text/html\n\n";#输出HTTP头
 - print qq~<html>
 - <head>
 - <title>用户登陆界面</title>
 - <meta http-equiv=';content-type'; content=';text/html; charset=gb2312';>
 - <LINK href=';http://www.gsfchina.org/css/style.css'; type=text/css rel=stylesheet>
 - </head>
 - <body background="../image/bg19.jpg">
 - <TABLE cellSpacing=0 cellPadding=0 width=770 align=center border=0>
 - <tr><td> </td></tr>
 - <tr><td> </td></tr>
 - <tr><td> </td></tr><tr><td class=3dfontA align=center>用户登陆</td></tr>
 - <form name =login action=sdel.cgi method=POST>
 - <input type=hidden name=action value=login>
 - <tr><td align=center>用户名:<input type=text size=12 name=u></td></tr>
 - <tr><td align=center>密 码:<input type=password size=12 name=pass></td></tr>
 - <tr><td align=center><input type=submit value=" 登 陆 " style="border-left: 1px dotted #ff0000; border-right: 1px dotted #ff0000; border-top: 1px dotted #ff0000; border-bottom:1px dotted #ff0000;background-color: ##e1e9ff">  <input type=reset value=" 重 来 " style="border-left: 1px dotted #ff0000; border-right: 1px dotted #ff0000; border-top: 1px dotted #ff0000; border-bottom:1px dotted #ff0000;background-color: ##e1e9ff"></td></tr>
 - <tr><td> </td></tr>
 - <tr><td class=3dfontC align=center> 本系统在完善当中</td></tr>
 - </form></table>
 - </body></html>~;
 - exit;
 - }
 - sub clean {
 - my $string = shift;
 - return ';'; unless (defined $string);
 - $string =~ s|\t| |g;
 - $string =~ s|&|&|g;
 - $string =~ s|<!--|<!--|g;
 - $string =~ s|-->|-->|g;
 - $string =~ s|<script|<script|ig;
 - $string =~ s|>|>|g;
 - $string =~ s|<|<|g;
 - $string =~ s|"|"|g;
 - $string =~ s!^\s+!!;
 - $string =~ s!\s+$!!;
 - $string =~ s|  |  |g;
 - $string =~ s|\n|<br>|g;
 - $string =~ s|\r||g;
 - $string =~ s|\_\_(.+?)\_\_||g;
 - return $string;
 - }
 
  复制代码 PHP程序:- <?php
 - $password = "isphp" ;// 管理密码,运行时会要求输入,一定要修改掉。不然程序无法运行。
 - //////  下面是主程序,不必修改  ////////////////////////////////////////////////////////
 - echo ';<style>';
 - . ';body{font-family:Verdana; font-size:12px; background-color:#fcfcfc}';
 - . ';input{font:12px Tahoma} ';
 - . ';</style>';;
 - if ( $password == "isphp" )
 - {
 - echo "<h3 align=center>您没有修改管理密码,为避免不安全,请修改成其它的!</h3>";
 - echo "<center>修改方法如下:<br>"
 - . ';用记事本打开 本文件(rm.php), 将第二行的 <font color=red>$password = "isphp" </font> 中的 isphp 改成您想要的密码, 再上传至服务器</center>';;
 - exit;
 - }
 - if ( !IsSet($HTTP_POST_VARS[';dirname';]) ) 
 - {
 - $self = $_SERVER[';PHP_SELF';] ? $_SERVER[';PHP_SELF';] : $PHP_SELF;
 - echo "<form action=\"{$self}\" method=post name=delform><center><font color=red>欲删除的文件或文件夹</font>: <input name=dirname style=\"color:red\"> "
 - . "密码: <input type=password name=pass size=6> <input type=submit value=\"确定\"></center></form>"; 
 - echo " <SCRIPT> document.delform.dirname.focus() </SCRIPT> ";
 - }
 - else 
 - {
 - if ( $password != $HTTP_POST_VARS[';pass';] )
 - {
 - exit("<script>alert(';错误的管理员密码, 无法继续操作! 如果您忘了密码,可以在本文件的第二行查到密码!';);</script>");
 - }
 - $dir_name = $HTTP_POST_VARS[';dirname';];
 - if ( is_file( $dir_name ) )
 - {
 -         if ( unlink($dir_name) )echo "Del file \"$dirname\" successfully!<br>"; 
 -                 elseecho "<FONT COLOR=RED>Fail to del file \"$dirname\"!</FONT><br>"; 
 - }
 - else
 - {
 -         CleanDir($dir_name);
 - if ( rmdir($dir_name) )echo "Remove dir \"$dirname\" successfully!<br>";
 -             else                 echo "<FONT COLOR=RED>Fail to Remove dir \"$dirname\"!</FONT><br>"; 
 - }
 - } 
 - function CleanDir($dir)
 - {
 - $handle=opendir($dir);
 - while ( $file=readdir($handle) )
 - {
 - if ( ($file==".") || ($file=="..") ) continue;
 - if ( is_dir("$dir/$file") )
 - {
 - CleanDir("$dir/$file");
 - if ( rmdir("$dir/$file") )echo "Remove dir \"$dir/$file\" successfully!<br>";
 -                         elseecho "<FONT COLOR=RED>Fail to Remove dir \"$dir/$file\"!</FONT><br>"; 
 - } 
 - else      
 - { 
 - if ( unlink("$dir/$file") )     echo "Del file \"$dir/$file\" successfully!<br>"; 
 - else                 echo "<FONT COLOR=RED>Fail to del file \"$dir/$file\"!</FONT><br>";  
 - }
 - }
 - closedir($handle);
 - }
 - ?> 
 
  复制代码 |   
 
 
 
 
                     我是一个呼吸着现在的空气而生活在过去的人 
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠 
                                     我已习惯了孤独,爱上孤独 
                                 他让我看清了自我,还原了自我 
                             让我再静静的沉思中得到快乐和满足 
                                   再孤独的世界里我一遍又一遍 
                                   不厌其烦的改写着自己的过去 
                                             延伸到现在与未来 
                                       然而那只是泡沫般的美梦 
                                 产生的时刻又伴随着破灭的到来 
                         在灰飞烟灭的瞬间我看到的是过程的美丽 
                                      而不是结果的悲哀。。。 
 | 
 
 
 
 |