deleting user account
Please,
How to remove all files created by user except ~user ? |
Quote:
and execute. Code:
rm -r -f * |
I guess I should ask my question another way:
How to delete all those files created by user that are outside of ~user/ |
Quote:
Find the UID of the user using Code:
id username Code:
find / -user UID -exec rm '{}' \; |
Hi,
If you want to delete all files from user X, but not those in user X's home directory (say /home/X) find is probably the tool to use. find / -user X | grep -v "/home/X" The above command will look for files belonging to user X (-user X), the grep -v part will exclude the home dir of X. If this is to your liking add the following to actually remove the files that are found: | xargs rm The complete command will look like this: find / -user X | grep -v "/home/X" | xargs rm Hope this helps. @vinaytp: Your solution will remove all files from the specific user, including those in the homedir!!! |
Thx druuna very much. I knew that find / -user X -exec rm{} \; would remove ALL files so I just didn't know how to exclude HOME.
But I have another question - How to remove such files (created by X ) but after removing user X and his or her HOME? Suppose I don't remember X ID |
Hi,
The username is represented by -user <name>, the -id <id> for the numeric uid. Once you remove a user (userdel), the system cannot show the name anymore (name<-> uid is done from the passwd file). Instead it will show the UID that a file has. I.e: If the user is still present: -rw-r--r-- 1 druuna internet 296 2009-10-27 15:12 load27078.sql If druuna is deleted, the above line will show as (501 being druuna's UID): -rw-r--r-- 1 501 users 296 2009-10-27 15:12 load27078.sql If you delete one or more users and later find files like this: -rw-r--r-- 1 501 users 296 2009-10-27 15:12 load1.sql -rw-r--r-- 1 502 users 296 2009-10-27 15:12 load2.sql -rw-r--r-- 1 503 users 296 2009-10-27 15:12 load3.sql it is not possible to find out which file belonged to which user....... Good practice would be to first remove the files a certain user created and then remove the user itself. Hope this clears things up. |
Hi,
Yes, druuna, you're right. Your explanation has really cleared things up. Thank you. |
All times are GMT -5. The time now is 11:40 AM. |