(新增修改版)一个删除不用内核模块目录的小脚本,仅仅是为了自己方便。
发布时间:2009-12-12 06:47:19来源:红联作者:一米短绳
[i=s] 本帖最后由 一米短绳 于 2009-12-12 15:24 编辑 [/i]
可以再加其它的东西,比如删除旧的/boot/下文件,旧的这个那个,昨天敲键盘频繁的我手麻,为了方便就写了这个小脚本。[code]#!/bin/bash
#Description:
# In order to be comvenient to delete the modules ,which is the old
# kernel's.It will detect "/lib/modules/x.y.z*" directory for removing
# each specified old modules.
#
#2009/12/12 一米短绳
#
PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
if [ "$1" ] ; then
version="$1"
else
read -p "Input the kernel version:" version
fi
if [ -d "/lib/modules/$version" ] ; then
echo "Remove the /lib/modules/$version?"
else
echo "$version is NOT exist! Exit!" && exit
fi
read -p "y or n ?" choice
if [ "$choice" == "y" ] ; then
rm -rf /lib/modules/$version && echo "Complete!"
else
echo "Script suspended!" && exit
fi[/code]再附上修改版,增加了选项功能,让我更爽~~哈哈 不用再输入挺长的version了。而且将目的目录由之前内定的/lib/modules/ 改写成一个变量来代替,这样可以把这个脚本再作点手脚,很简单的就能改成方便的交互式“rm“,免去了rm后面跟一堆文件名的麻烦。[code]#!/bin/bash
#Description:
# In order to be comvenient to delete the modules ,which is the old
# kernel's.It will detect "/lib/modules/x.y.z*" directory for removing
# each specified old modules.
#Tips:
# <1>...You can use the variable of "$1" in the script's options' region.
# (e.g.: ./**.sh 2.6.18.old , the variable of "$1" is "2.6.18.old" in this instance.) ;
#Option:
# ./**.sh ( OR "sh **.sh" )
# ./**.sh x.y.z ("x.y.z" is the old kernel's version)
#
#2009/12/12 一米短绳
#
PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
DIR_foe=/lib/modules/
if [ "$1" ] ; then
version="$1"
else
echo "This is a name-list of directory to contain kernel modules in your system curently."
ls -1 $DIR_foe | nl -s " ==> "
echo "You can select the number( in order to access easily)"
read -p "Remove number:" number
version=$(ls -1 $DIR_foe | sed -n "${number}p")
fi
echo $version
if [ -d "$DIR_foe$version" ] ; then
echo "Remove the $DIR_foe$version?"
else
echo "$version is NOT exist! Exit!" && exit
fi
read -p "y or n ?" choice
if [ "$choice" == "y" ] ; then
rm -rf $DIR_foe$version && echo "Complete!"
else
echo "Script suspended!" && exit
fi
[/code]下面是最终的执行效果图:
[attach]28517[/attach]