Solved

Locating files owned by a particular user

Posted on 2011-03-12
2
508 Views
Last Modified: 2012-05-11
Hi Group

I have been trying to delete files that are owned by a particular user in a linux machine. Please verify if my logic is correct.

Firstly I search for all files owned by a user :

find / -user bob

and then pass the rm -rf command to that expression using the exec command

Question 1. Will the find option used above find all files owned by user bob?

Question2. Am I correct in parsing the rm -rf command using the exec option?

Any feedback is highly appreciated.

Thanks.
0
Comment
Question by:tuxracer
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 125 total points
ID: 35119874
1,  That will find all files, dirs, links, devices etc, owned by bob.

You should use the -type f option, eg:

find / -type f -user bob

2.  Don't use the -r option to rm.  If you tried that without use the -type f, then if bob owned a directory with files owned by other users, then you would have deleted the lot.

You could use -exec, but if your version of find has the -delete option, that's better, eg:

find / -type f -user bob -delete

alternatively, you can combine find with xargs

find / -type f -user bob -print0 | xargs -0 rm -f

note that the -print0 and -0 make sure filenames with spaces in them are processed.




0
 

Author Closing Comment

by:tuxracer
ID: 35119885
Excellent!!!

Thanks for your feedback! Much appreciated :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question