Solved

Locating files owned by a particular user

Posted on 2011-03-12
2
514 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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