LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-27-2009, 03:57 AM   #1
newk
LQ Newbie
 
Registered: Sep 2009
Posts: 20

Rep: Reputation: 0
deleting user account


Please,

How to remove all files created by user except ~user

?
 
Old 11-27-2009, 04:27 AM   #2
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Quote:
Originally Posted by newk View Post
Please,

How to remove all files created by user except ~user

?
go to user's home directory

and execute.

Code:
rm -r -f *
 
Old 11-27-2009, 05:02 AM   #3
newk
LQ Newbie
 
Registered: Sep 2009
Posts: 20

Original Poster
Rep: Reputation: 0
I guess I should ask my question another way:

How to delete all those files created by user that are outside of ~user/
 
Old 11-27-2009, 05:15 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Quote:
Originally Posted by newk View Post
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 !!!
 
0 members found this post helpful.
Old 11-27-2009, 05:18 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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!!!

Last edited by druuna; 11-27-2009 at 05:20 AM.
 
1 members found this post helpful.
Old 11-27-2009, 05:29 AM   #6
newk
LQ Newbie
 
Registered: Sep 2009
Posts: 20

Original Poster
Rep: Reputation: 0
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
 
Old 11-27-2009, 05:58 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
1 members found this post helpful.
Old 11-27-2009, 06:05 AM   #8
newk
LQ Newbie
 
Registered: Sep 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Hi,

Yes, druuna, you're right. Your explanation has really cleared things up. Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
is it legitimate and allowed and can be done to make another user account set uid and gid to null 0 to make another root account with different name and possibly not damage the debian system creating and using that new account BenJoBoy Linux - Newbie 12 01-29-2006 10:02 AM
deleting account @ LQ .hack LQ Suggestions & Feedback 4 08-04-2005 08:13 AM
X wont start after deleting user account RockmanExe Mandriva 7 03-30-2004 08:03 PM
Deleting a user account from prompt lozz1978 Linux - Newbie 8 01-15-2004 07:43 AM
Deleting account Jose Muņiz LQ Suggestions & Feedback 2 07-09-2003 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration