Linux userdel命令使用详解
Linux userdel命令 用于删除给定的用户,以及与用户相关的文件。若不加选项,则仅删除用户帐号,而不删除相关文件。
用法
userdel [options] LOGIN
选项
-f, –force
强制删除用户,即使用户当前已登录;它同时删除用户的家目录,mail spool,即使这个目录任然被其他用户使用,如果文件/etc/login.defs
中USERGROUPS_ENAB
定义为yes
,同时存在一个和将要删除的用户名同名的组,那么删除这个组,即使这个组是其他用户的主组。注意:此选项很危险,可能会使系统处于不一致状态
-h, –help
显示帮助信息-r, –remove
删除与用户相关的所有文件——R, –root CHROOT_DIR
Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.-P, –prefix PREFIX_DIR
Apply changes in the PREFIX_DIR directory and use the
configuration files from the PREFIX_DIR directory. This option
does not chroot and is intended for preparing a cross-compilation
target. Some limitations: NIS and LDAP users/groups are not
verified. PAM authentication is using the host files. No SELINUX
support.
实例
userdel命令很简单,比如我们现在有个用户comptechs,其家目录位于/var
目录中,现在我们来删除这个用户:
1 | userdel comptechs # 删除用户comptechs,但不删除其家目录及文件; |
请不要轻易用-r
选项;他会删除用户的同时删除用户所有的文件和目录,切记如果用户目录下有重要的文件,在删除前请备份。
其实也有最简单的办法,但这种办法有点不安全,也就是直接在/etc/passwd
中删除您想要删除用户的记录;但最好不要这样做,/etc/passwd
是极为重要的文件,可能您一不小心会操作失误。