Solved

Locating files owned by a particular user

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What language/protocol is the Angular Chat? 2 73
Choosing CentOS 16 79
Rate limit for DNS queries 7 73
how to print sub line with  sed /awk /perl in bash file 11 23
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…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

786 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