Solved

Locating files owned by a particular user

Posted on 2011-03-12
2
505 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

919 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

22 Experts available now in Live!

Get 1:1 Help Now