LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find files? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-files-4175420141/)

sunveer 08-03-2012 04:07 AM

How to find files?
 
How to find all the files of a particular user and copy and paste them in a directory?

pixellany 08-03-2012 04:13 AM

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.

sunveer 08-03-2012 04:20 AM

Quote:

Originally Posted by pixellany (Post 4744812)
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.

Nylex 08-03-2012 04:24 AM

You can use the find command for things like this. Its "-user" test is what you want to be looking at.

Mr. Alex 08-03-2012 06:26 AM

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.

sunveer 08-03-2012 07:18 AM

Quote:

Originally Posted by Mr. Alex (Post 4744906)
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.

Mr. Alex 08-03-2012 07:32 AM

Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
Code:

echo $USER

sunveer 08-03-2012 07:53 AM

Quote:

Originally Posted by Mr. Alex (Post 4744950)
Did you typed in your username correctly? I mean username in your GNU/Linux system.
It should be as in
Code:

echo $USER

Yes

414N 08-03-2012 07:57 AM

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?

Mr. Alex 08-03-2012 08:05 AM

414N, you're right. Looked it up and found corrections. OP, see URL.

sunveer 08-03-2012 08:23 AM

Will this cmd serve the purpose?

#find / -user UNAME | cpio -pdumv /path/

Mr. Alex 08-03-2012 08:27 AM

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 \;

sunveer 08-03-2012 08:36 AM

Quote:

Originally Posted by Mr. Alex (Post 4744986)
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 03:52 AM.