LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2012, 02:41 AM   #1
Farah_s
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
how to locate owned files for some user and copy it to another directory


dears how i can locate files which owned by some user and copy it to another directory



i use
find / -user "usrname" -exec cp -t /targetdirectory {} \;

is that right or i have to use


find / -user "usrname" -exec cp -art /targetdirectory {} \;
 
Old 03-13-2012, 03:15 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
It is a good practice to wrap your braces in single quotes, to prevent the shell from interpreting them. I'm not sure if it would work without doing so.

You need the braces before the target directory of the cp command, find will insert its results, in between the braces as it executes the command..

Code:
$ find ~/ -user "someuser" -type d -exec cp -rv '{}' /dev/null \;
This will copy all directories owned by someuser, and their contents, to /dev/null. preserving the directory structure.

The cp options (-art), are going to depend on what your intended result is. Whether you want to preserve the directory structure or not. This would have an effect on the find command too.
 
Old 03-13-2012, 05:01 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
Also you face the issue that you may not have permission to look in certain directories, hence access to the person's files may be restricted.
 
Old 03-13-2012, 06:47 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
Quote:
Originally Posted by fukawi1 View Post
You need the braces before the target directory of the cp command, find will insert its results, in between the braces as it executes the command..
Since the -t option of cp is used this is not necessary.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Find all files owned by a user and copy them to a temp folder mikezoch Linux - Newbie 3 11-28-2011 06:02 PM
Can't copy files to root owned files! Help! christophercheeseman Linux - General 6 02-01-2011 07:29 PM
why can I remove files owned by another user in a directory of mine? melcataclysm Linux - Newbie 5 10-18-2009 06:06 AM
Can you make any files and folders created within a directory owned by another user?? helptonewbie Linux - Newbie 13 12-14-2007 04:21 PM
locate and copy files - without directory tree rodda Linux - General 1 01-16-2005 02:10 AM


All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration