in Uncategorized

递归删除相同文件名文件的脚本


#!/bin/sh
#Author: SwordGreen
#Date: 11/10/2005

fileName=$1
delFile()
{
    for dirName in *
    do
      if [ -d "$dirName" ]
          then
          cd "$dirName"
          delFile
          if [ -e $fileName ]
              then
              echo "Deleting $PWD/$fileName"
              rm -f $fileName
          fi
          cd ..
      fi
    done
}
if [ ! $# = 1 ]
    then
    echo "Usage:delfile filename"
    else
          delFile

          if [ -e $1 ]
              then
              echo "Deleting $PWD/$1"
              rm -f $1
          fi
fi 

Write a Comment

Comment