Remove all files and directories owned by a specific user


Transfered from Linux Config Disqus comments:

Hi, how do I remove all files owned by a certain user. What I need is to find all files and directories and remove them system wide.
The tool which may come handy to is a find command. Find command will find all files and directories owned by a specific user and execute rm command to remove them. The following command will find and remove all files within /home/ directory owned by a user “student”. The following command is executed as root user:
NOTE: replace /home with your target directory.

# find /home/ -user student -exec rm -fr {} \; 

The following command will do the same however, it will search for a file and directories which belong to a group student:

# find /home/ -group student -exec rm -fr {} \;

However, if you are trying to remove a user from the system along with his/her files and directories you may find deluser command also useful. deluser will remove user from the system as well as remove all files associated with this user. The command below will demonstrate just that where the target is a user “student”

# deluser --remove-all-files student