LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   deleting user account (https://www.linuxquestions.org/questions/linux-newbie-8/deleting-user-account-771866/)

newk 11-27-2009 03:57 AM

deleting user account
 
Please,

How to remove all files created by user except ~user

?

vinaytp 11-27-2009 04:27 AM

Quote:

Originally Posted by newk (Post 3771168)
Please,

How to remove all files created by user except ~user

?

go to user's home directory

and execute.

Code:

rm -r -f *

newk 11-27-2009 05:02 AM

I guess I should ask my question another way:

How to delete all those files created by user that are outside of ~user/

vinaytp 11-27-2009 05:15 AM

Quote:

Originally Posted by newk (Post 3771221)
I guess I should ask my question another way:

How to delete all those files created by user that are outside of ~user/

Try this

Find the UID of the user using
Code:

id username
TO remove files
Code:

find / -user UID -exec rm '{}' \;
Cheers !!!

druuna 11-27-2009 05:18 AM

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!!!

newk 11-27-2009 05:29 AM

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

druuna 11-27-2009 05:58 AM

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.

newk 11-27-2009 06:05 AM

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.