还在为不小心输了rm -rf *而错删了文件烦恼吗?还在为cd到某个目录后每次都还要输ls命令吗?用alias的强大功能解决吧!
把下面代码写入家目录的.bashrc中:
alias cd='cdls() { [ -n "$1" ] && cd "$1" || cd; ls; }; cdls '
alias rm='saferm'
saferm()
{
argstr=`echo $* | grep "\-f"; echo $* | grep "\-rf"; echo $* | grep "\-fr"`
if test -z "$argstr"
then
mkdir .trash &> /dev/null
mv $* .trash -f &> /dev/null
echo "Removing files to .trash succeed"
else
read -p "Are you sure to remove those files? (yes/no): " answer
if [ "$answer" = "yes" ]
then
/bin/rm $*
fi
fi
}