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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-03-2012, 04:07 AM
|
#1
|
Member
Registered: Jul 2012
Posts: 139
Rep:
|
How to find files?
How to find all the files of a particular user and copy and paste them in a directory?
|
|
|
08-03-2012, 04:13 AM
|
#2
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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.
|
|
|
08-03-2012, 04:20 AM
|
#3
|
Member
Registered: Jul 2012
Posts: 139
Original Poster
Rep:
|
Quote:
Originally Posted by pixellany
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.
|
|
|
08-03-2012, 04:24 AM
|
#4
|
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464
Rep:
|
You can use the find command for things like this. Its "-user" test is what you want to be looking at.
|
|
|
08-03-2012, 06:26 AM
|
#5
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep:
|
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.
|
|
|
08-03-2012, 07:18 AM
|
#6
|
Member
Registered: Jul 2012
Posts: 139
Original Poster
Rep:
|
Quote:
Originally Posted by Mr. Alex
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.
|
|
|
08-03-2012, 07:32 AM
|
#7
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep:
|
Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
|
|
|
08-03-2012, 07:53 AM
|
#8
|
Member
Registered: Jul 2012
Posts: 139
Original Poster
Rep:
|
Quote:
Originally Posted by Mr. Alex
Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
|
Yes
|
|
|
08-03-2012, 07:57 AM
|
#9
|
Member
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 649
Rep:
|
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.
|
08-03-2012, 08:05 AM
|
#10
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep:
|
414N, you're right. Looked it up and found corrections. OP, see URL.
|
|
|
08-03-2012, 08:23 AM
|
#11
|
Member
Registered: Jul 2012
Posts: 139
Original Poster
Rep:
|
Will this cmd serve the purpose?
#find / -user UNAME | cpio -pdumv /path/
|
|
|
08-03-2012, 08:27 AM
|
#12
|
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238
Rep:
|
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 \;
|
|
|
08-03-2012, 08:36 AM
|
#13
|
Member
Registered: Jul 2012
Posts: 139
Original Poster
Rep:
|
Quote:
Originally Posted by Mr. Alex
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.
|
|
|
All times are GMT -5. The time now is 10:04 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|