在CentOS中,要刪除多個用戶,可以使用deluser命令結合循環來實現。以下是一個示例腳本,用于刪除指定的多個用戶:
#!/bin/bash
# 用戶名列表,用空格分隔
usernames="user1 user2 user3"
# 遍歷用戶名列表并刪除每個用戶
for username in $usernames; do
# 檢查用戶是否存在
if id "$username" &>/dev/null; then
# 刪除用戶及其主目錄和郵件池
deluser --remove-home --remove-mail "$username"
echo "已刪除用戶: $username"
else
echo "用戶不存在: $username"
fi
done
將上述腳本保存為一個文件,例如delete_users.sh,然后通過以下命令使其可執行:
chmod +x delete_users.sh
最后,運行腳本以刪除指定的用戶:
./delete_users.sh
請注意,在運行此腳本之前,請確保您已備份所有重要數據,因為刪除用戶及其主目錄是不可逆的操作。