linux下删除用户不仅仅是userdel -r 那么简单。
如果你删除用户时,该用户有许多进程正在进行,你是不是要一个个kill掉再删除;
如果你成功删除该用户后,系统中还有需要改用户的文件是不是还要删除。
如上,岂不麻烦。下面的脚本可以帮你快速删除一个或多个用户。
#!/bin/bash #delete user from system #by slitobo 2017/6/2 #check user is root [ `id -u` -ne 0 ] && echo "Please change to root user ..." && exit 10 #check arguments number [ $# -lt 1 ] && echo "Usage: $0 user1 [user2] ..." && exit 11 #use list USER=($@) for i in ${USER[@]} do if id $i &> /dev/null;then read -n 1 -p "Comfirm Delete User "$i" [y=comfirm,other key=cancel]:" SURE case $SURE in y|Y) echo ps -u $i --no-heading | awk ‘{print $1}‘ | xargs kill -9 &> /dev/null #kill user pid find / -user $i -exec rm -rf {} \; &> /dev/null #delete user files userdel $i &> /dev/null #delete user echo "The user $i deleted" ;; *) echo echo "$i delete not successful" ;; esac fi done
本文出自 “遥西向南” 博客,请务必保留此出处http://slitobo.blog.51cto.com/12957087/1931891
linux下删除用户脚本----不是userdel -r 那么简单
原文地址:http://slitobo.blog.51cto.com/12957087/1931891