#!/bin/bash
#如果运行命令时未指定需要删除的用户帐号,则返回提示信息并退出。
if [ -z $1 ]
then
 echo "please enter a username!"
#否则统计passwd文件中指定用户的记录数
else
 n=$(cat /etc/passwd |
 grep $1 |
 wc -1 )
#如果需要删除的用户帐号在系统中不存在,则返回提示信息并退出。
if [ $n -lt 1 ]
then
 echo "the user does not exist!"
#否则杀死用户对应的进程并删除该用户的所有文件
else
 echo "kill the following process:"
 echo
 p

#否则 杀死相关进程
else
kill -9 $pid
fi
echo
echo "finding all of the files own by" $1

find / -depth -user $1 2> /dev/null >file.list
echo
echo "all of files own by "$1" have been list in the file 'files.list',are you sure to delete all of the files ? [ y|n ]"

read ans
if [ "ans"="y" ]
then
echo
echo "remove all the files own by"$1

#删除用户的所有文件和目录
find / -depth -user $1 -exec rm -Rf { } \; 2> /dev/null
echo
echo "all of the files have been removed !"
fi
echo
echo "removing the user"$1
#删除用户帐号
sleep 5
userdel $1
echo

#提示用户已经被删除
echo "the user has been removed !"
fi
fi
fi

 

 

相关文章:

  • 2021-05-20
  • 2022-12-23
  • 2021-07-11
  • 2021-08-07
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2021-11-21
  • 2021-07-02
  • 2021-12-10
  • 2022-02-07
  • 2021-12-28
相关资源
相似解决方案