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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-27-2009, 03:57 AM
|
#1
|
LQ Newbie
Registered: Sep 2009
Posts: 20
Rep:
|
deleting user account
Please,
How to remove all files created by user except ~user
?
|
|
|
11-27-2009, 04:27 AM
|
#2
|
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707
Rep:
|
Quote:
Originally Posted by newk
Please,
How to remove all files created by user except ~user
?
|
go to user's home directory
and execute.
|
|
|
11-27-2009, 05:02 AM
|
#3
|
LQ Newbie
Registered: Sep 2009
Posts: 20
Original Poster
Rep:
|
I guess I should ask my question another way:
How to delete all those files created by user that are outside of ~user/
|
|
|
11-27-2009, 05:15 AM
|
#4
|
Member
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707
Rep:
|
Quote:
Originally Posted by newk
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
TO remove files
Code:
find / -user UID -exec rm '{}' \;
Cheers !!!
|
|
0 members found this post helpful.
|
11-27-2009, 05:18 AM
|
#5
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
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 anon237; 11-27-2009 at 05:20 AM.
|
|
1 members found this post helpful.
|
11-27-2009, 05:29 AM
|
#6
|
LQ Newbie
Registered: Sep 2009
Posts: 20
Original Poster
Rep:
|
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
|
|
|
11-27-2009, 05:58 AM
|
#7
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
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.
|
11-27-2009, 06:05 AM
|
#8
|
LQ Newbie
Registered: Sep 2009
Posts: 20
Original Poster
Rep:
|
Hi,
Yes, druuna, you're right. Your explanation has really cleared things up. Thank you.
|
|
|
All times are GMT -5. The time now is 06:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|