都知道刪除用戶用userdel -r USERNAME,-r表明把用戶相對應的目錄一併刪除,那麼,假如疏忽了忘記加參數,會有什麼結果,今天我嘗試了一下。linux
#首先建立用戶user2,刪除後再從新添加:bash
[root@localhost ~]# useradd user2 [root@localhost ~]# userdel user2 [root@localhost ~]# useradd user2 useradd: warning: the home directory already exists. Not copying any file from skel directory into it. Creating mailbox file: File exists #沒錯,顯示家目錄已存在,而且,mailbox文件存在。由於刪除用戶時候沒加-r選項,查看/home裏面是否真存在該目錄: [root@localhost ~]# ll /home total 60 drwx------. 2 ab1 ab1 4096 Aug 16 02:13 ab1 drwx------. 2 ab2 ab2 4096 Aug 16 02:13 ab2 drwx------. 2 ab3 ab3 4096 Aug 16 02:14 ab3 drwx------. 2 mageia mageia 4096 Aug 20 21:38 linux drwx------. 2 root root 16384 Aug 6 07:18 lost+found drwx------. 2 tom tom 4096 Aug 17 01:51 tom drwx------. 2 tom1 tom1 4096 Aug 17 01:51 tom1 drwx------. 4 user user 4096 Aug 20 04:21 user drwx------. 2 user2 user2 4096 Aug 21 14:10 user2 #是否刪除/home/user2便可?咱們嘗試一下: [root@localhost ~]# rm -rf /home/user2 [root@localhost ~]# useradd user2 useradd: user 'user2' already exists [root@localhost ~]# userdel user2 [root@localhost ~]# useradd user2 Creating mailbox file: File exists #這個就是一開始咱們只刪除home目錄下對應的文件,並無刪除mailbox裏的文件,該文件會存放在哪裏? 咱們查看一下userdel的幫助手冊,其中-r命令裏有這樣的描述顯示該命令做用區域: home directory itself and the user′s mail spool: [root@localhost ~]# man userdel -r, --remove Files in the user′s home directory will be removed along with the home directory itself and the user′s mail spool. Files located in other file systems will have to be searched for and deleted manually. The mail spool is defined by the MAIL_DIR variable in the login.defs file. [root@localhost ~]# ls /var/spool/mail ab1 ab2 ab3 mageia mandriva openstack slackware tom tom1 user user2 [root@localhost ~]# rm /var/spool/mail/user2
刪除該文件並從新建立user2,成功。ide
由此可知,刪除用戶userdel 加參數-r是多麼重要。學習
那麼問題來了,建立用戶會生成什麼文件?rem
目前得知的是/etc/passwd, /etc/shadow, 但這兩個都只是添加記錄,it
建立文件夾的有/home/USERNAME,/var/spool/mail/USERNAME 至於其餘地方有沒有,等待後續深刻學習吧。class