LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-03-2012, 04:07 AM   #1
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Rep: Reputation: Disabled
How to find files?


How to find all the files of a particular user and copy and paste them in a directory?
 
Old 08-03-2012, 04:13 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
cp -R /home/username <new path>
OR
cp -R /home/username/Documents <new path>
replace <new path> with the desired destination

Some more detail on what you are doing will probably get a better answer.
 
Old 08-03-2012, 04:20 AM   #3
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post
Code:
cp -R /home/username <new path>
OR
cp -R /home/username/Documents <new path>
replace <new path> with the desired destination

Some more detail on what you are doing will probably get a better answer.
I want that whatever file that is owned by a user in the entire filesystem must be searched, not only its /home directory and cp in a new directory.
 
Old 08-03-2012, 04:24 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You can use the find command for things like this. Its "-user" test is what you want to be looking at.
 
Old 08-03-2012, 06:26 AM   #5
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Code:
# find / -user sunveer -exec cp -iv /desired/dir {} \;
  • "/" is where to search. In this example it's the entire filesystem - all mounted devices.
  • "sunveer" is your user here and
  • "/desired/dir" is where you wanna copy those files.
 
Old 08-03-2012, 07:18 AM   #6
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Mr. Alex View Post
Code:
# find / -user sunveer -exec cp -iv /desired/dir {} \;
  • "/" is where to search. In this example it's the entire filesystem - all mounted devices.
  • "sunveer" is your user here and
  • "/desired/dir" is where you wanna copy those files.
This command runs with no error but it didn't find any files.
 
Old 08-03-2012, 07:32 AM   #7
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
Code:
echo $USER
 
Old 08-03-2012, 07:53 AM   #8
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Mr. Alex View Post
Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
Code:
echo $USER
Yes
 
Old 08-03-2012, 07:57 AM   #9
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649

Rep: Reputation: 190Reputation: 190
Isn't the cp line missing a -t option to designate /desired/dir as the destination directory? Otherwise, shouldn't the file to be copied ({}) appear first than the destination directory?
 
1 members found this post helpful.
Old 08-03-2012, 08:05 AM   #10
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
414N, you're right. Looked it up and found corrections. OP, see URL.
 
Old 08-03-2012, 08:23 AM   #11
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Original Poster
Rep: Reputation: Disabled
Will this cmd serve the purpose?

#find / -user UNAME | cpio -pdumv /path/
 
Old 08-03-2012, 08:27 AM   #12
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Wrap your code up with forum tags.

I don't know about cpio, didn't work with it. What's wrong with suggested command?
Code:
# find /where/to/search -user sunveer -exec cp -ipv {} /where/to/copy \;
 
Old 08-03-2012, 08:36 AM   #13
sunveer
Member
 
Registered: Jul 2012
Posts: 139

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Mr. Alex View Post
Wrap your code up with forum tags.

I don't know about cpio, didn't work with it. What's wrong with suggested command?
Code:
# find /where/to/search -user sunveer -exec cp -ipv {} /where/to/copy \;
Nothing wrong with the command. Just asking for knowledge.

Thanks.
 
  


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
find hidden files from wild card path using 'find' nagendrar Linux - Newbie 5 10-13-2011 10:48 PM
linux find to find files with multiple patterns subu_s Programming 6 12-15-2010 12:15 AM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Is there a way to find recently created/edited files without using find? BrianK Linux - General 2 10-15-2007 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:04 AM.

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
Open Source Consulting | Domain Registration