Linux Shell腳本 清除指定目錄下的無效符號鏈接

腳本功能:清理$1給定目錄下無效的符號鏈接,如果$1爲空則清理當前目錄下無效的符號鏈接


#!/bin/bash

if [ ! -d $1 ];then
    echo -e "\033[31mError, $1 Is not a directory"
    exit 3
fi
declare -i Sum=0
for Links in $(find $1 -type l);do
    stat -L $Links > /dev/null 2> /dev/null
    if [ $? -gt 0 ];then 
        rm $Links && echo -e "\033[31m$Time delete   $Links\033[m"
        let Sum++
    fi
done
echo
echo -e "\033[1mdelete $Sum link"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章