Solved

Locating files owned by a particular user

Posted on 2011-03-12
2
504 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
Comment Utility
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
Comment Utility
Excellent!!!

Thanks for your feedback! Much appreciated :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now