Ubuntu: How to delete a user & its home folder safely?


I just created a new user & its home folder & need to delete it now & also I cant find my old user's Downloads,Documents,Pictures,etc folder in /home/olduser & also .Xauthority file. Dont know how it deleted. I executed startx command by pressing Alt+Ctrl+F3when new user wasnt able to log in.

I deleted user from Users & Groups but its home folder didnt get deleted. How can I fix this?

  • How can I delete new user's home folder safely?

  • How can restore my old documents,downloads,folder?

  • If not then how can I create brand new /home folder & link with OS?


to list all users :

cut -d: -f1 /etc/passwd  

To remove user :

sudo userdel username  

To remove home directory :

sudo rm -r /home/username  

To add a home directory to an existing user :

create a home directory

chown this directory for the user

sudo usermod -d /home/directory user  


You can use the more advanced deluser command:

sudo deluser --remove-home user  

You can also try the the --remove-all-files option. From man deluser:

By  default,  deluser  will  remove  the user without removing the home  directory, the mail spool  or any other files on the  system  owned  by  the  user.  Removing  the home directory and mail spool can be achieved  using the --remove-home option.    The --remove-all-files option removes all files on the system owned  by  the  user.  Note  that  if you activate both options --remove-home will  have no effect because all files including the home directory and  mail  spool are already covered by the --remove-all-files option.  

As can be expected, the second option may take a while to complete.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »